Back
How can I add a key in python directory after it's creation ?
I already tried .add() method but it doesn't work.
Use this code to add multiple/single keys in a dictionary, for single key the code will have less computational overhead:
>>> y = {2:3}>>> print y{2: 3}>>> q = {4:5, 6:7, 8:9}>>> y.update(q)>>> print y{2: 3, 4: 5, 6: 7, 8: 9}
>>> y = {2:3}>>> print y{2: 3}
>>> q = {4:5, 6:7, 8:9}>>> y.update(q)>>> print y{2: 3, 4: 5, 6: 7, 8: 9}
Hope this helps.
30.9k questions
32.9k answers
500 comments
665 users