-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
105 lines (80 loc) · 1.75 KB
/
dictionary.py
File metadata and controls
105 lines (80 loc) · 1.75 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Dictionary
# 1
my_dictionary = {
"Name": "Paul",
"Gender": "Male",
"Status": "Single"
}
print(my_dictionary)
# 2
my_dictionary = dict(
Name="Paul",
Gender="Male",
Status="Single"
)
print(my_dictionary)
# Print specific values in an element
print(my_dictionary['Gender'])
print(my_dictionary.get('Status'))
print(my_dictionary.get('Name'))
print(my_dictionary['Name'])
# Edit a specific value element
my_dictionary['Status'] = "Complicated"
print(my_dictionary)
# Adding a key value elements
my_dictionary['BirthDate'] = '31/01/2006'
print(my_dictionary)
my_dictionary['Residence'] = 'Nakuru'
print(my_dictionary)
my_dictionary['Email'] = 'w.paul.g@proton.me'
print(my_dictionary)
# Copying from one dictionary to another
my_dictionary_2 = my_dictionary.copy()
print(my_dictionary_2)
# Dictionary Length
# Number of elements in a dictionary
print(len(my_dictionary))
# Remove element
# obj__.pop
my_dictionary.pop('Status')
print(my_dictionary)
print(my_dictionary_2)
# del obj__[el__]
del my_dictionary_2['Email']
print(my_dictionary_2)
print(my_dictionary)
# Clear Dictionary
# obj__clear()
my_dictionary.clear()
print(my_dictionary)
print(my_dictionary_2)
# del obj__
del my_dictionary
print(my_dictionary_2)
#
if 'Name' in my_dictionary_2:
print('Name found')
else:
print('Name not found')
# Print Dict Values
for value in my_dictionary_2:
print(my_dictionary_2[value])
#
for key in my_dictionary_2:
print(key)
#
for key, value in my_dictionary_2.items():
print(key, value)
#
shop1 = {
'Maize Flour': 100,
'Wheat Flour': 200,
'Millet Flour': 210,
}
print(shop1)
if 'Maize Flour' in shop1:
print('There is Maize Flour')
else:
print('There is No Maize Flour')
shop1['Meat'] = '1000'
print(shop1)