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*

Abbeville TX

Bakerhill TX

Abernant GA

Bangor GA

Alabaster AL

Berry AL

*Csv i needed*

Alabaster AL

Berry AL

Abernant GA

Bangor GA

Abbeville TX

Bakerhill TX

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)
lsNearCities.append(state_and_cities)
sorted(lsNearCities, key=operator.itemgetter(1,0))
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to