Python: sorting a list of

Ding! Discouraging word!

 

'' ' 
Part of the word: 
Zoo English [zuː] 
United States [zuː] 
. The n-zoo; 
[sentence] He took his son Christopher to the zoo. 
He took his son Christopher went to the zoo. 
[Other] plural: zoos 

Internationalization 
English [ˌɪntəˌnæʃnəlaɪzeɪʃn] 
United States [ˌɪntərˌnæʃnələzeɪʃn] 
. The n-international co-management; internationalization; 
. [Sentence] It also shows the historic process which modern China was brought into the modernization and internationalization 
It also reflects modern China is incorporate a modern and historical track the process of internationalization. 

blueberry English [bluːbəri] 
United States [bluːberi] 
the n-blue berry cranberries, blueberries (produced in North America, edible);. 
[Examples] Every inn had a picturesque name - the Black Locust Inn, the Blueberry Inn. 
Each hotel there is a unique name, such as "acacia hotel", "blueberries hotel." 
[Other] complex: blueberries 

this word is very important! ! ! 
reverse Britain [rɪvɜːs]
United States [rɪvɜːrs]
. v reversed; completely changed; the exact opposite; revocation, repeal (decision, legal, etc.); the reverse; the reverse order; 
the n-opposite case (or thing); Behind; back; back; reverse gear; 
ADJ. opposite; negative; reverse; back; back; 
[sentence] they have made it clear they will not reverse the decision to increase prices 
they have made it clear that the decision does not change the price increases. 
[Other] third person singular: reverses complex: reverses participle: reversing past: reversed past participle: reversed 
'' '

 

Ding! Code discouraging!

 

list1 = ['orange', 'apple', 'zoo', 'internationalization', 'blueberry']
print(list1)  # ['orange', 'apple', 'zoo', 'internationalization', 'blueberry']
# sorted函数 默认按首字母顺序排序(a,b,c,d,e...)
list2 = sorted(list1)
print(list2)  # ['apple', 'blueberry', 'internationalization', 'orange', 'zoo']

# 反转? True 反转!
list3 = sorted(list1,reverse=True)
print(list3)  # ['zoo', 'orange', 'internationalization', 'blueberry', 'apple']

# 通过key关键字参数指定根据字符串长度进行排序而不是默认的字母表顺序
list4 = sorted(list1,key=len)
print(list4)  # ['zoo', 'apple', 'orange', 'blueberry', 'internationalization']

# 给列表对象发出排序消息直接在列表对象上进行排序
list1.sort(reverse=True)
print(list1)  # ['zoo', 'orange', 'internationalization', 'blueberry', 'apple']
# 这种行为破坏了原有的数据(也能叫编辑~~~)

 

Published 52 original articles · won praise 34 · views 2621

Guess you like

Origin blog.csdn.net/weixin_38114487/article/details/103849962