sorting list by multiple criteria and grouping alphabetically in python
farookrceg at gmail.com
Sat Apr 18 09:56:46 CEST 2015
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 can it be done? Please help me in this.
*Csv at present*
*Csv i needed*
And my code is
lsNearCities = 
idx = layer.fieldNameIndex('name') #name of the attribute column with
the cities in it
idx1 = layer.fieldNameIndex('state')
nearCity = f.attributes()[idx]
state = f.attributes()[idx1]
state_and_cities = nearCity + "," + str(state)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list