sorting list by multiple criteria and grouping alphabetically in python

Chris Angelico rosuav at gmail.com
Sun Apr 19 03:59:43 EDT 2015


On Sat, Apr 18, 2015 at 5:56 PM, Ahamed Farook <farookrceg at gmail.com> wrote:
> sorted(lsNearCities, key=operator.itemgetter(1,0))

This doesn't sort the list, it constructs a new one - and then
promptly discards it. What you want is the .sort() method on the list
object. As your code is incomplete, I can't say if there are any other
issues in it, but try switching over to the sort method and seeing if
that does what you want.

All the best!

ChrisA



More information about the Python-list mailing list