Skip to content

Instantly share code, notes, and snippets.

@mayankdawar
Created August 7, 2020 20:48
Show Gist options
  • Save mayankdawar/591469f5e60318ee148a365ee1e1ce94 to your computer and use it in GitHub Desktop.
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.
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
@me010101
Copy link

me010101 commented Apr 3, 2023

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment