Creating a new dict in Python


Question

I want to build a dictionary in Python. However, all the examples that I see are instantiating a dictionary from a list, etc . ..

How do I create a new empty dictionary in Python?

1
400
11/8/2015 4:43:09 AM

Accepted Answer

Call dict with no parameters

new_dict = dict()

or simply write

new_dict = {}
590
11/8/2015 3:49:24 AM

You can do this

x = {}
x['a'] = 1

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon