+ 1
Dictionary
How to create a dictionary in python
2 Antwoorden
+ 1
Keep learning Introduction to Python.
You can create a dictionary as:
my_dict = {
"key1" : "value1",
"key2" : "value2",
...
}
0
Hi! How to Create a Dictionary?
Method 1: Using Curly Braces {}
Dictionary can be created by placing a sequence of elements within curly {} braces, separated by a 'comma'.
Method 2: Using the dict() Constructor
Be careful! If you don't use the key:value construct in curly brackets {} and simply list the elements separated by commas, you will get a different type of data - a set
dic_1 = {1: 'Abba', 2: 'Beatles', 3: 'Metallica'}
print(dic_1, end="\n\n")
# Method 2: Using the dict() Constructor
# create dictionary using dict() constructor
dic_2 = dict(a = "Geeks", b = "for", c = "Geeks")
print(dic_2)
https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK/python-dictionary/?ysclid=mhzu1na1k2706144968
https://pythonguides.com/dictionaries/



