Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
3 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 (46k 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
0 votes
1 answer
asked Sep 17, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...