I have a list with a dictionary and I want to add data from another dictionary to that dictionary.
This is the list with the original dictionary:
lista = [{'nombre' : 'Jose', 'edad' : 18}]
This is the dictionary with the data to add:
dict = {'cursos': ['Python','Flask','JavaScript']}
I want to achieve the following result:
resultado = [{'nombre' : 'Jose', 'edad' : 18, 'cursos': ['Python','Flask','JavaScript']}]
I think it should be done with the zip function but I don't get the result I need.
I use Python 3.6. Thank you very much in advance.
Elements of the form can be added to the dictionary:
Then:
Sure, the name is being placed
'cursos'
manually as a key and the programming doesn't work that way, so you must take the index and value to insert it into the other dictionary dynamically:Plus
As expected, there are other, more Pythonic ways to solve this:
Using dict.update()
Plus+
Python 3.9+ d | other
changing
dict
byd
If you want it in a new variable:
If you don't mind modifying
lista
(with permission from @abulafia):