[python] Sort dictionary into list based on another dict · GitHub
文章推薦指數: 80 %
[python] Sort dictionary into list based on another dict ... dict_key = {'a': 1, 'b': 3, 'c': 2} # The order should be "a c b". # sort dict_to_sort by using ... Skiptocontent Allgists BacktoGitHub Signin Signup Sign in Sign up {{message}} Instantlysharecode,notes,andsnippets. sheenzhaox/sort_dict_by_another_dict.py LastactiveMay9,2022 Star 4 Fork 0 Star Code Revisions 2 Stars 4 Embed Whatwouldyouliketodo? Embed Embedthisgistinyourwebsite. Share Copysharablelinkforthisgist. Clonevia HTTPS ClonewithGitorcheckoutwithSVNusingtherepository’swebaddress. LearnmoreaboutcloneURLs DownloadZIP [python]Sortdictionaryintolistbasedonanotherdict Raw sort_dict_by_another_dict.py ThisfilecontainsbidirectionalUnicodetextthatmaybeinterpretedorcompileddifferentlythanwhatappearsbelow.Toreview,openthefileinaneditorthatrevealshiddenUnicodecharacters. LearnmoreaboutbidirectionalUnicodecharacters Showhiddencharacters dict_to_sort={'a':123,'b':'test','c':'-'} dict_key={'a':1,'b':3,'c':2}#Theordershouldbe"acb" #sortdict_to_sortbyusingdict_key sorted_pair_list=sorted(dic.items(),key=lambdax:dict_key.get(x[0])) #thelistofvalues value_list=zip(*sorted_pair_list)[1] Copylink daluu commented Feb4,2019 Ibelieveinline6,dict.items()shouldbedict_to_sort.items() Sorry,somethingwentwrong. Signupforfree tojointhisconversationonGitHub. Alreadyhaveanaccount? Signintocomment Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.
延伸文章資訊
- 1[python] Sort dictionary into list based on another dict · GitHub
[python] Sort dictionary into list based on another dict ... dict_key = {'a': 1, 'b': 3, 'c': 2} ...
- 2How to Sort a Dictionary by Value in Python - Stack Abuse
We can sort a dictionary with the help of a for loop. First, we use the sorted() function to orde...
- 3Python: Sort a Dictionary by Values - datagy
Sort a Python Dictionary by Values Using dict.items and Sorted ... The Python sorted() function a...
- 4How to Sort a Dictionary by Value in Python - Stack Abuse
- 5How to Sort a Dictionary by Value in Python | Career Karma
To sort a dictionary by value in Python you can use the sorted() function. Python's sorted() func...