Skip to content
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!

You are viewing a single comment. View All
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).