Created
August 7, 2020 20:48
-
-
Save mayankdawar/591469f5e60318ee148a365ee1e1ce94 to your computer and use it in GitHub Desktop.
Provided is a nested data structure. Follow the instructions in the comments below. Do not hard code.
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 = {'data': ['finding', 23, ['exercises', 'hangout', 34]], 'window': ['part', 'whole', [], 'sum', ['math', 'calculus', 'algebra', 'geometry', 'statistics',['physics', 'chemistry', 'biology']]]} | |
# Check to see if the string data is a key in nested, if it is, assign True to the variable data, otherwise assign False. | |
if 'data' in nested: | |
data = True | |
else: | |
data = False | |
# Check to see if the integer 24 is in the value of the key data, if it is then assign to the variable twentyfour the value of True, otherwise False. | |
if 24 in nested['data']: | |
twentyfour = True | |
else: | |
twentyfour = False | |
# Check to see that the string 'whole' is not in the value of the key window. If it's not, then assign to the variable whole the value of True, otherwise False. | |
if 'whole' not in nested['window']: | |
whole = True | |
else: | |
whole = False | |
# Check to see if the string 'physics' is a key in the dictionary nested. If it is, assign to the variable physics, the value of True, otherwise False. | |
if 'physics' in nested: | |
physics = True | |
else: | |
physics = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check to see if the string 'data' is a key in nested, if it is, assign True to the variable data, otherwise assign False.
data='data' in nested.keys()
Check to see if the integer 24 is in the value of the key data, if it is then assign to the variable twentyfour the value of True, otherwise False.
twentyfour=24 in nested.values()
Check to see that the string 'whole' is not in the value of the key window. If it's not, then assign to the variable whole the value of True, otherwise False.
whole='whole' not in nested['window']
Check to see if the string 'physics' is a key in the dictionary nested. If it is, assign to the variable physics, the value of True, otherwise False.
physics='physics' in nested.keys()