Feed on
Posts
Comments

to custom sort a list on the fly, try using the lambda function to do a quick definition of the cmp function.  for instance, to sort the list ‘ids’, using each ‘id’ value in an ancillary dictionary ‘id_dict’:

ids.sort(cmp=lambda a,b:id_dict[b] – id_dict[a])


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

Did I get this wrong? Let me know!

Trackback URI | Comments RSS