-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
49 lines (34 loc) · 1.15 KB
/
dictionary.py
File metadata and controls
49 lines (34 loc) · 1.15 KB
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
# key value pair
# don't allow duplicate
Student={
"stu_id":"std978",
"name":"sanoop",
"age":"22",
"email":"sanoops58@gmail.com",
"class":["school","highschool","college"],
"stu_id":"2023578" #don't allow duplicates instead of overwrite the existed id
}
print(Student["age"]) #lookup with key
print(Student.get("college")) # lookup with value get none instead of error
print(Student.keys())
print(Student.values())
for key, value in Student.items():
print(key,":",value)
Student.update({"dob": "20-10-2002"})
print(Student)
Student.update({"dob":"20-10-2003"})
print(Student)
Student.pop("class")
print(Student)
print(Student["class"][2]) #find the value by index
for study in Student["class"]:
print(study)
trips= {
"UUISF7":{"trip_id":"UUISF7","pickup":"Chennai","drop":"airport","fare":589},
"UUISi6":{"trip_id":"UUISi6","pickup":"Thiruvanthapuram","drop":"central","fare":890},
"UUIS57":{"trip_id":"UUIS578","pickup":"ooty","drop":"hillstation","fare":345}
}
print(trips["UUISF7"]["pickup"])
for Trip_id, details in trips.items():
print(Trip_id)# print key value
print(details["pickup"],"->",details["drop"])