yoh, Sort dict
have a problem with sorting dict by value!!! found something interesting on http://code.activestate.com/recipes/304440/ by Nick Coghlan
let's see
>>d = {'a':0,'b':1,'c':2}
>>d
#will get
{'a':0,'c':2,'b':1}
some solution from Nick
>>from operator import itemgetter
>>print sorted(d.items(),key=itemgetter(1))
#we get
[('a':0),('b':1),('c':2)] # >>>>> a list of tuples
it might be useful in the future!!!:) thank nick and activestate
let's see
>>d = {'a':0,'b':1,'c':2}
>>d
#will get
{'a':0,'c':2,'b':1}
some solution from Nick
>>from operator import itemgetter
>>print sorted(d.items(),key=itemgetter(1))
#we get
[('a':0),('b':1),('c':2)] # >>>>> a list of tuples
it might be useful in the future!!!:) thank nick and activestate
Nice! thank you this's my problem!
ReplyDelete