Batteries Included

A neat property of Python’s sort function is that it automatically sorts list of tuples by the first value of the tuple, this means that if you have a list, lets say of files and their sizes and you want to sort by filesize, you can do: >>> a = [(200, ‘foo.txt’), (100, ‘bar.txt’)] >>> a.sort() >>> a [(100, […] Also tagged