students_grade
is a list that contains tuples, each having a student name and a grade, both in a string.
For example:
students_grade = [('jon','88'), ('bran', '100'), ('arya','93'), ('dan', '88')]
The goal is to create a new list with the same tuples ordered by the grades:
[('jon','88'), ('dan', '88',' ('arya','93'),('bran','100')]
Tried solving it using a dictionary, however I noticed that '100' < '93'
returns True
, so I tried sorting the dictionary by int(values)
, however got TypeError
.
dic = {}
for i in students_grades:
dic[i[0]] = i[1]
sorted_keys = sorted(dic.keys(), key = int(dic.get), reverse=True)
without the int(dic.get)
it works fine. Why does it fail?