I have i txt file that i need to sort the info in by a certain element. this would be the original file
Wheaton,Will,7 Parker,Peter,9 Apple,Adam,1 Jones,Mike,10 Potter,Harry,7 it the file to be sorted by the third element so that the file will read
Apple,Adam,1 Wheaton,Will,7 Potter,Harry,7 Parker,Peter,9 Jones,Mike,10 I have tried using
allItems = [] for i in info: data = i.rstrip('\n').split(',') allItems.append(data) allItems.sort(key=lambda x: x[2]) but it didnt work. how can i organize by list element. Also will python automatically alphabetize the lines or will I have to do it sepatately
key=itemgetter(2)instead of that lambda? *from operator import itemgetterdatatolistsas the thing to sort.