Created
August 7, 2020 20:52
-
-
Save mayankdawar/e9d7ab236cd92e4b7d2307f77e679274 to your computer and use it in GitHub Desktop.
Given the dictionary, nested_d, save the medal count for the USA from all three Olympics in the dictionary to the list US_count.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nested_d = {'Beijing':{'China':51, 'USA':36, 'Russia':22, 'Great Britain':19}, 'London':{'USA':46, 'China':38, 'Great Britain':29, 'Russia':22}, 'Rio':{'USA':35, 'Great Britain':22, 'China':20, 'Germany':13}} | |
US_count = [] | |
for i in nested_d: | |
temp = nested_d[i]['USA'] | |
US_count.append(temp) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using list comprehension reduces the code to one line.
But pylint does not like the code above. It prefers the usage of .items() method.
Or the use of the list comprehension.