Dec-26-2021, 05:28 AM
(Dec-26-2021, 02:00 AM)BashBedlam Wrote: Something like this maybe?
the_dictionary_list = { 'Color': ['Amarillo.png', 'Blanco.png','Rojirosado.png', 'Turquesa.png', 'Verde_oscuro.png', 'Zapote.png'], 'Cuerpo': ['Cuerpo_cangrejo.png'], 'Fondo': ['Oceano.png'], 'Ojos': ['Antenas.png', 'Pico.png', 'Verticales.png'], 'Pinzas': ['Pinzitas.png', 'Pinzotas.png', 'Pinzota_pinzita.png'], 'Puas': ['Arena.png', 'Marron.png', 'Purpura.png', 'Verde.png']} for key, value in the_dictionary_list.items () : answer = input (f'Would like to add "None" to {key}? ') if answer.lower () == 'y' : the_dictionary_list [key].insert (0, 'None') print (key, value, '\n')
Thank you for your answer , I also developed another one sometime after I created this thread, here it is:
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: the_dictionary_list[key_entrada].insert(0, 'None') 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: ") else: key_entrada = input('That input does not exist in the dictionary, try again, Type only a valid key name:') if entrada == 'n': print('weno') break elif entrada != 'y' or entrada != 'n': entrada = input("Invalid Input, Type 'y' or 'n' without single quotation marks: ")Now the only thing that doesn't let me sleep is to figure out how to avoid executing the
the_dictionary_list[key_entrada].insert(0, 'None')
if the current the_dictionary_list
already has a key with 'None'
as value inside its respective array , do you know how could I do that to improve the code above?