-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
44 lines (36 loc) · 927 Bytes
/
dictionary.py
File metadata and controls
44 lines (36 loc) · 927 Bytes
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
phones= {
"ashu" :99,
"prerna" : 93,
"pranay" : 95,
"papa" : 79
}
print(type(phones)) #type
print(len(phones)) #to find the length
print(phones["ashu"]) #to find the value of given key
print(phones.get("prerna")) #it is also used to get the value of a key
print(phones.keys()) #to print all keys present in dictionary
print(phones.values()) #to print all values
print("the sum of all key value is: ",sum(phones.values()))
#change the value
phones["ashu"]=78
print(phones)
#add new keys and value
phones["ria"]=90
print(phones)
#add a new dictionary to old dictionary
phones_1={
"ram":56,
"krish":13,
"jay":45
}
phones.update(phones_1)
print(phones)
#remove a key value
phones.pop("ashu")
print(phones)
#remove last key value
phones.popitem()
print(phones)
#empty the dictionary
phones.clear()
print(phones.items())