-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDictionary.py
48 lines (36 loc) · 1.07 KB
/
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
48
#*Dictionary can call the data in Dictionary by useing keyword
#Way to use dictionary
scores = {"M" : 100, "L" : 80, "A" : 70, "T" : 60};
scores['bobby'] = 10; #append bobby
number = {1 : "one", 2 : "Two"};
print(scores);
print(number);
print("=============================================");
#How to use dictionary
#display
print("T =>", scores["T"])
print("L =>",scores["L"]);
#update data
scores["T"] = scores["T"] + 100;
scores["M"] = 200
print(scores["T"]);
print(scores["M"]);
print("==============================================");
#check dictionary
if "K" in scores.keys() :
print(scores["smith"]);
else :
print("no smith in scores");
#loop with dictionary
alphabets = {"A" : 1, "B" : 2, "C" : 3, "D" : 4}
for k, v in alphabets.items():
print(k, v)
# iterate through keys
print('Key :', end = " ");
for k in alphabets.keys():
print(k, end = " ");
print();
# iterate through values
print('Value :', end = " ");
for v in alphabets.values():
print(v, end = " ");