Dec-26-2021, 10:03 AM
(This post was last modified: Dec-26-2021, 10:03 AM by noahverner1995.)
(Dec-26-2021, 09:42 AM)ibreeden Wrote:if None in the_dictionary_list[key_entrada]: print("None is already in the list") else: the_dictionary_list[key_entrada].insert(0, 'None')
Thank you again! Once more, I will update the final version of this program, now the user can choose whether adding a
'None'
value to the arrays of one of the available keys only once, or not adding anything at all :def existe(key, value, diccionario): return key in diccionario and value in diccionario[key] entrada = input('All right, do you want to add a "None" item to an array in the dictionary? (y/n):') while True: if entrada == 'y': key_entrada = input('Cool, now tell me at which key do you want me to add a "None" item? Type only a valid key name:') while True: if key_entrada in the_dictionary_list: if existe(key_entrada, 'None', the_dictionary_list) == False: the_dictionary_list[key_entrada].insert(0, 'None') print('\u001b[43mthe_dictionary_list IS UPDATED:\033[0m') print(the_dictionary_list) print('\n') key_entrada = input('Done, do you want to add another one? (y/n):') if key_entrada == 'n': entrada = 'n' break if key_entrada == 'y': key_entrada = input('Cool, now tell me at which key do you want me to add a "None" item? Type only a valid key name:') else: key_entrada = input("Invalid Input, Type 'y' or 'n' without single quotation marks:") while True: if key_entrada == 'n': entrada = 'n' break if key_entrada == 'y': key_entrada = input('Cool, now tell me at which key do you want me to add a "None" item? Type only a valid key name:') break elif key_entrada != 'n' or key_entrada != 'y': key_entrada = input("Invalid Input, Type 'y' or 'n' without single quotation marks:") if existe(key_entrada, 'None', the_dictionary_list) == True: key_entrada = input('That input DOES ALREADY EXIST in the dictionary, try again with another key name:') elif entrada == 'n': break else: key_entrada = input('That input does not exist in the dictionary, try again, Type only a valid key name:') if entrada == 'n': break elif entrada != 'y' or entrada != 'n': entrada = input("Invalid Input, Type 'y' or 'n' without single quotation marks:")