+1 vote
2 views
in Python by (10.2k points)
edited by

How can I add a key in python directory after it's creation ?

I already tried .add() method but it doesn't work.

1 Answer

0 votes
by (46.1k points)
edited by

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}

Hope this helps. 

Related questions

0 votes
1 answer
asked Sep 17 in Python by Sammy (47.7k points)
0 votes
1 answer
0 votes
1 answer
asked Aug 27 in Python by Sammy (47.7k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...