I read in python a log that contains name, memory, ncalls for each row
and save this as tuple list where each element is a tuple (name, memory, ncalls)
sometimes need to sort the list according name other times according memory or ncalls.
The problem if I simply use the code
mylist=sorted(mylist, key=itemgetter(2))
the list is sorted using the desired parameter but python consider the parameter like a String and I get this result
item3, 45, 1
item1, 4, 12
item4, 65, 3
item2, 65, 5
the desired result would be
item3, 45, 1
item4, 65, 3
item2, 65, 5
item1, 4, 12
because 3 and 5 are smaller than 12
How could I solve this without change the way i save the list?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…