-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data Dictionary.py
49 lines (34 loc) · 1.02 KB
/
Data Dictionary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Dict = {}
print("Empty Dictionary: ")
print(Dict)
# Creating a Dictionary with Integer Keys
Dict = {1: 'Geeks', 2: 'For', 3: 'Geeks'}
print("\nDictionary with the use of Integer Keys: ")
print(Dict)
# Creating a Dictionary with Mixed keys
Dict = {'Name': 'Geeks', 1: [1, 2, 3, 4]}
print("\nDictionary with the use of Mixed Keys: ")
print(Dict)
# Creating a Dictionary with dict() method
Dict = dict({1: 'Geeks', 2: 'For', 3: 'Geeks'})
print("\nDictionary with the use of dict(): ")
print(Dict)
# Creating a Dictionary with each item as a Pair
Dict = dict([(1, 'Geeks'), (2, 'For')])
print("\nDictionary with each item as a pair: ")
print(Dict)
#Dynamic Dicticnary creation
sDict = {x.upper(): x*3 for x in 'coding'}
print (sDict.items())
print (sDict)
print (sDict.keys())
print (sDict.values())
#Accessing Key and Value through loops
sDict = {x.upper(): x*3 for x in 'coding'}
for key in sorted(sDict.keys()):
print (key, sDict[key])
for key in sDict:
print(key)
for k, v in sDict.items():
print(k)
print(v)