-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
62 lines (47 loc) · 918 Bytes
/
dictionary.py
File metadata and controls
62 lines (47 loc) · 918 Bytes
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
d = dict()
m = {"name":"divisha","age":34,7:8}
print(m['name'])
#print(m["gjh"])
print(m.get("n","not available"))
m[7] = 99
m[56] = "hgjy"
print(m)
del m[7]
print(m)
print(m.keys())
print(m.values())
print(m.items())
#shallow
l = m
m["name"]="molly"
print(l)
print(m)
#deep
s = m.copy()
m["name"] = 22
print(m)
print(s)
for keys in m.keys():
print(m[keys])
for key,val in m.items():
print(f"{key}:{val}")
students = {
"student1":{1:2,3:4},
"student2":{5:2,6:4}
}
print(students["student1"][1])
for studentid,studentinfo in students.items():
print(studentid,studentinfo)
for item in studentinfo.items():
print(item)
squares = {x:x**2 for x in range(5)}
print(squares)
numbers = (1,2,2,3,3,3,4,4,4,4)
freq = {}
for i in numbers:
freq[i] = freq.get(i, 0) + 1
print(freq)
dict1 = {"a":1,"b":2}
dict2 = {"b":3,"c":4}
merged_dict = {**dict1,**dict2}
print(merged_dict)