The exercise I'm currently taking has three different dictionaries. What I wanted to do was update the first dictionary with keys and values from the other two with two different for loops like this.
def give_me_new(dic1, dic2, dic3):
for key, value in dic2.items():
dic1.update({key:value})
for k, v in dic3.items():
dic1.update({k:v})
After I updated, I housed all the keys inside a variable.
some_keys = dic1.keys()
What I decided to do was utilize a while loop to check to see if the key exists inside the dictionary. I created it like this
value = False
while value == False:
check_key = input('Lets check to see if key has been updated: ')
if check_key not in some_keys:
input('Nope, not in there. Press enter to try again')
elif check_key in some_keys:
return 'It is in there', dic1
value = True
However, each time the input is prompted and the value is entered, it keeps showing that the key is not in there. What exactly happened inside the entire function created to cause this issue to come up?
Down below is the entire script created, please let me know what exactly I've done wrong.
def give_me_new(dic1, dic2, dic3):
for key, value in dic2.items():
dic1.update({key:value})
for k, v in dic3.items():
dic1.update({k:v})
some_keys = dic1.keys()
value = False
while value == False:
check_key = input('Lets check to see if key has been updated: ')
if check_key not in (some_keys):
input('Nope, not in there. Press enter to try again')
elif check_key in (some_keys):
return 'It is in there', dic1
value = True
print(give_me_new({1:10, 2:20}, {3:30, 4:40}, {5:50,6:60}))