-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path040.DictionaryMethods.py
63 lines (52 loc) · 1.08 KB
/
040.DictionaryMethods.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
d={
0:"zero",
1:"one",
2:"two",
3:"three",
4:"four",
5:"five",
6:"six",
7:"seven",
8:"eight",
9:"nine",
"IV":"four"
}
d2 = {
7:"lucky seven",
10:"ten",
3:"this is the new three",
}
pantry_items = ['chicken','spam','egg','bread','lemon']
#form keys from a list:-
# new_dict = dict.fromkeys(pantry_items,0)
# print(new_dict)
#old method to iteratre over keys:-
#keys = d.keys()
#print(keys)
#new method to iterate over keys:-
#for item in d.keys():
# print(item)
#update method from one dictionary to another
# d.update(d2)
# print(d)
# print()
# d.update(enumerate(pantry_items))
# for key,value in d.items():
# print(key,value)
#.values() method
v = d.values()
print(v)
d[10] = "ten"
print(v)
print("four" in v)
print("eleven" in v)
# keys = list(d.keys())
# values = list(v)
# if "four" in values:
# index = values.index("four")
# key = keys[index]
# print(f"{d[key]} was found with the key {key}")
print()
for key, value in d.items():
if value == "four":
print(f"{d[key]} was found with the key {key}")