-
Notifications
You must be signed in to change notification settings - Fork 0
/
access files.py
84 lines (76 loc) · 1.42 KB
/
access files.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
thisdict = {
"brand" : "Ford",
"model" : "Mustang",
"year" :2003
}
x = thisdict["model"]
print(x)
print()
x = thisdict.get('brand')
print(x)
print()
x = thisdict.keys()
print(x)
print()
#add new item to the original dictionary
car = {
"brand" : "Ford",
"model" : "Mustang",
"year" :2003
}
x = car.keys()
print(x) #before change
print()
car["colour"] = "White"
print(x) #after change
print()
x = thisdict.values()
print(x)
print()
#make change in original dictionary
car = {
"brand" : "Ford",
"model" : "Mustang",
"year" :2003
}
x = car.values()
print(x) #before change
print()
car["year"] = 2005
print(x) #after change
print()
#get item
x = car.items()
print(x)
print()
#change items
car = {
"brand" : "Ford",
"model" : "Mustang",
"year" :2003
}
x = car.items()
print(x) #before change
car["model"] = "fiesta"
print(x) #after change
print()
#item list updation
thisdict = {
"brand" : "Ford",
"model" : "Mustang",
"year" :2003
}
x = thisdict.items()
print(x) #before change
thisdict["colour"] = "red"
print(x) #after change
print()
#check if key exists
thisdict = {
"brand" : "Ford",
"model" : "Mustang",
"year" :2003
}
if "model" in thisdict:
print("Yes, 'model' is one of the keys in thisdict dictionary")
#change items and update dictionaries are same as above methods