Computer Science, asked by 2shrestha28, 6 months ago

Given the same dictionary, medals, now sort by the medal count. Save the three countries with the highest medal count to the list, top_three. Write the code.

medals = {'Japan':41, 'Russia':56, 'South Korea':21, 'United States':121, 'Germany':42, 'China':70}
[PYTHON]

Answers

Answered by faizanurrahman838
0

Answer:

use inbuilt sort function with lambda to sort specific value in iterator. StackOverflow it.

Answered by Anonymous
1

medals = {'Japan':41, 'Russia':56, 'South Korea':21, 'United States':121, 'Germany':42, 'China':70}

def g(k,d):

return d[k]

ks = medals.keys()

top_three = sorted(ks,key=lambda x : g(x,medals),reverse = True)

Similar questions