Skip to content
← Back to Community
How can I alphabetically order the output!
Profile icon
MaxwellAdams

I need to get the data that is outputted by the program currently, in Alphabetical order. I am unaware of how to do this and would appreciate help from anyone who may know how!

Voters
Profile icon
Kalid147Alang
Profile icon
MaxwellAdams
Comments
hotnewtop
Profile icon
Codejira

Currently you are sorting the values of row[2] only.

For sorting a list of lists by items of the inner list you can use operator.itemgetter. Try this:

import operator # do stuff print(sorted(data, key=operator.itemgetter(2))

to sort by your third column (index 2).