Last active
April 20, 2018 13:46
-
-
Save johnmcc/79be8f1a9ad88ccfbcfb327c875f1c95 to your computer and use it in GitHub Desktop.
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
# Meet the Beatles: | |
beatles = [ | |
{"name": "John Lennon", "birth_year": 1940, "death_year": 1980, "instrument": "piano"}, | |
{"name": "Paul McCartney", "birth_year": 1942, "death_year": None, "instrument": "bass"}, | |
{"name": "George Harrison", "birth_year": 1943, "death_year": 2001, "instrument": "guitar"}, | |
{"name": "Ringo Starr", "birth_year": 1940, "death_year": None, "instrument": "drums"} | |
] | |
# Use the `beatles` list above to answer the following questions: | |
# 1. John Lennon also plays guitar. Access the `instrument` key in his dictionary and change its value: | |
# 2. Write a function which takes in the list of band members as a parameter, | |
# and returns a list of all the Beatles' names: | |
# Expected result: ['John Lennon', 'Paul McCartney', 'George Harrison', 'Ringo Starr'] | |
# 3. Write a function which takes in the list of band members as a parameter, | |
# and returns a list of the members who are still alive | |
# (i.e. they have no value for `death_year`) | |
# Return the full dictionary for each member | |
# Expected result: [ | |
# {'name': 'Paul McCartney', 'birth_year': 1942, 'death_year': None, 'instrument': 'bass'}, | |
# {'name': 'Ringo Starr', 'birth_year': 1940, 'death_year': None, 'instrument': 'drums'} | |
# ] | |
# 4. Combine the above two functions to return the names of all the members who are alive: | |
# Expected result: ['Paul McCartney', 'Ringo Starr'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment