Obtaining values from columns in python

You need to sort your data. Once you sort your data, you can print out the data as you desire.

#brief example (but not a direct solution!)
aList = [ ["citya","22"]   \
                ["cityc","44"]   \
                ["cityb","55"]   \ 
aSortedList = sorted(alist, key=lamda x:x[1])
#now pick how you want to get your information from the sorted list
#hint you have already read the information. 

But you do NOT have your data linked directly. So either create a new list with all the information OR track the information as you go.

Part of the issue is that you are trying to do everything immediately as you read the file. The data read has NOT been sifted through. No sorting, only read. Finding minimums and maximums do NOT need to be sorted, but then you’ll need to TRACK the information.

if (new_value > max1):
   max3 = max2
   max2 = max1
   max1 = new_value

if (new_value > max2 and new_value < max1):

and you’ll have to loop through it all.

Tracking is good if the information is given all at once. But if the information changes, referencing the data might be easier later.

Leave a Comment