Python | Dictionary initialization with common dictionary

Sometimes, while working with dictionaries, we might have an utility in which we need to initialize a dictionary with records values, so that they can be altered later. This kind of application can occur in cases of memoizations in general or competitive programming. Let’s discuss certain way in which this task can be performed.

Method : Using zip() + repeat()
The combination of these functions can be used to perform this particular task. In this, the Dictionary value is attached to the keys repeated using the repeat() by help of zip()





# Python3 code to demonstrate working of
# Dictionary initialization with common dictionary
# Using zip() + repeat()
from itertools import repeat
# initialization Dictionary 
test_dict = {'gfg' : 1, 'best' : 3}
# Using zip() + repeat()
# Dictionary initialization with common dictionary
res = dict(zip(range(4), repeat(test_dict)))
# printing result 
print("The dictionary with record values : " + str(res))


Output :

The dictionary with record values : {0: {'gfg': 1, 'best': 3}, 1: {'gfg': 1, 'best': 3}, 2: {'gfg': 1, 'best': 3}, 3: {'gfg': 1, 'best': 3}}
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.