Python size is sorted based on the value of the dictionary

Source: Internet
Author: User
Num_dict = {' A ': +, ' B ': ten, ' C ': 8, ' d ': 0} #方法1 # new_dict = sorted (Num_dict.items (), Key=lambda x:x[1]) # Print (Dict (new_d ICT)) #方法2def new_dict (a_dict):    b_dict = {}  #用于存放排序后的字典    values = sorted (A_dict.values ())   #把16, 10,8,0 sorting    Print (values)  #打印出  [0, 8, ten,] #接下来要匹配key值 for    i in    values: for k,v in        num_ Dict.items (): #所有的数据项取出来            if v==i:                b_dict[k] = v  #添加数据项到b_dict字典里    print (b_dict) new_dict (num_ Dict

  

Python size is sorted based on the value of the dictionary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.