Question
I have a structure that looks like this:
- {'key_info':(rank,raw_data1,raw_data2),'key_info2':....}
How-To
With help of API:sorted, you can do it this way:
Supplement
* Python Doc - Sorting HOW TO
* Sort a list by multiple attributes?
This is a blog to track what I had learned and share knowledge with all who can take advantage of them
>>> test_dict = {}
>>> test_dict['John'] = (18, 'Taiwan')
>>> test_dict['Ken'] = (22, 'American')
>>> test_dict['Peter'] = (16, 'Japan')
>>> test_dict['Mary'] = (30, 'China')
>>> test_dict
{'Ken': (22, 'American'), 'John': (18, 'Taiwan'), 'Peter': (16, 'Japan'), 'Mary': (30, 'China')}
>>> sorted(test_dict.keys(), key=lambda k: test_dict[k][0], reverse=True) # Sorting with age in descending order
['Mary', 'Ken', 'John', 'Peter']
>>> sorted(test_dict.keys(), key=lambda k: test_dict[k][1]) # Sorting with country name in ascending order
['Ken', 'Mary', 'Peter', 'John']
>>> test_dict['Winson'] = (29, 'Canada')
>>> test_dict['Jacy'] = (24, 'China')
>>> sorted(test_dict.keys(), key=lambda k: (test_dict[k][1], test_dict[k][0])) # Sorting with country, then age in ascending order
['Ken', 'Winson', 'Jacy', 'Mary', 'Peter', 'John'] # Jacy=(24, 'China'); Mary=(30, 'China')
Source From Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 # git clean -d -fx 方案2: 今天在服务器上 gi...
沒有留言:
張貼留言