Feb-08-2019, 04:25 PM
Just a advice,you are doing a unnecessary step with
klist
Larz60+.>>> medals = {'Japan':41, 'Russia':56, 'South Korea':21, 'United States':121, 'Germany':42, 'China':70} >>> sorted(medals.items(), key=lambda v: v[1]) [('South Korea', 21), ('Japan', 41), ('Germany', 42), ('Russia', 56), ('China', 70), ('United States', 121)]
(Feb-08-2019, 03:27 PM)farzankh Wrote: Save the three countries with the highest medal count to the list, top_three.
>>> medals = {'Japan':41, 'Russia':56, 'South Korea':21, 'United States':121, 'Germany':42, 'China':70} >>> sorted(medals.items(), key=lambda v: v[1], reverse=True)[:3] [('United States', 121), ('China', 70), ('Russia', 56)]