need help sorting a list of tuples in python 3
Go to solution
Solved by Nuluvius,
I'll let you sort your print formatting out. Basically you were sorting strings and not Integers.
in_file = open("scores.txt")high_scores = []for line in in_file: score, name = line.split(", ") high_scores += [(int(score), name)]print(high_scores)high_scores = sorted(high_scores, key=lambda tup: tup[0])print(high_scores)
[(3, 'Nuno Bettencourt\n'), (4, 'Jimi Hendrix\n'), (5, 'Lincoln Brewster'), (12, 'Eric Gales\n')]

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now