python - Cannot sort a set correctly -


uci = {'a+': 4.0, 'a': 4.0,'a-': 3.7,        'b+': 3.3, 'b': 3.0,'b-': 2.7,        'c+': 2.3, 'c': 2.0,'c-': 1.7,        'd+': 1.3, 'd': 1.0,'d-': 0.7,        'f': 0.0}  def top(student_info : {(str,str)}) -> {str}:     name_set = set()     x in sorted(student_info, key = lambda x: x[0][-1], reverse = true):                     print(x)  top({('alice','c'),('bobby','b-'),('carol','b-'),('david','d'),('evelyn','c+')}) 

i want sort set key of grade highest lowest. however, not give me right order. got is:

('bobby', 'b-') ('evelyn', 'c+') ('carol', 'b-') ('alice', 'c') ('david', 'd') 

any appreciated! thank

it's sorting correctly. have sorting last character in first item in tuple. key function going fed individual elements, ('alice', 'c'). x[0][-1] gets first element ('alice') , takes last character ('e'). output in reverse order.

what want

lambda x: uci[x[1]] 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -