Re: sorting list by multiple criteria and grouping alphabetically in python

2015-04-19 Thread Chris Angelico
On Sat, Apr 18, 2015 at 5:56 PM, Ahamed Farook 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

sorting list by multiple criteria and grouping alphabetically in python

2015-04-18 Thread Ahamed Farook
I have a list named "lsNearCities" which contains "states" and "cities" in it. And I write the values in the list to csv where the column will be in the order of city and state. And also I did sorting based on the state first and cities second. Now I want the csv to be printed as shown below. How c