mdsk.net
ǰλãҳ >> Ϊʲô python list sort >>

Ϊʲô python list sort

sort() ڶԭбָʹñȽϺָıȽϺ ﷨ sort()﷨ list.sort([func]) func -- ѡ, ָ˸òʹøòķ ֵ ÷ûзֵǻ...

ܼ򵥰 sort ֧ reverse ӣֱ˳ УԼС >>> l = [7, 3, 9, 1, 12, -8]>>> l.sort()>>> l[-8, 1, 3, 7, 9, 12]>>> l = [7, 3, 9, 1, 12, -8]>>> l.sort(reverse=True)>>> l[12, 9...

ֻҪǿɵ󶼿sorted sorted(itrearble, cmp=None, key=None, reverse=False) =źĬֵ Ĭģ ýУreverse=True ὫĽŵһµбУ Ƕiterable޸...

֪python sortʹÿŵģרΪpythonŻcʵ֡ ڵһӦһ죬numpy.arrayռʸߡnumpy.arrayӦñȽá ǶڲǼ򵥵numpy.arrayΪˣֻʹlist ...

set򼯺ϣpython֤ԪصĴ򡣴ӡȡڲ洢ṹʽ ľ֪ >>> set('012345678910') set(['1', '0', '3', '2', '5', '4', '7', '6', '9', '8']) ˵ǰƶάķʽģȰظ...

list.sort(key = int) key൱ڹֵбеÿֵʵϻתΪkey(value),Ϊ int(value) Ҳ ['1','2','11','22'].sort(key = int)൱[int('1'),int('2'),int('11'),int('22')].sort() keyΪlist ...

sort()reverse() бķֱӶԭбвsorted() Ǻ䷵صһµбdifang=['d','c','b','a']difang.sort()difang.sort(reverse=True)x=sorted(difang,re...

ΪlistsortûзֵġprintǸNone aList.sort()print aList

db.Account.find().sort([("UserName",pymongo.ASCENDING),("Email",pymongo.DESCENDING)])

Զkeyؼ >>> a=['abc','abcd','ab'] >>> a.sort(key=len) #ʹlenصĴС >>> a ['ab', 'abc', 'abcd'] keyreverseеģһ¾֪

վҳ | վͼ
All rights reserved Powered by www.mdsk.net
copyright ©right 2010-2021
磬ַϵͷzhit325@qq.com