-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictionary.py
57 lines (52 loc) · 1.11 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
49
50
51
52
53
54
55
56
57
dict1={"Alger":16,
"Blida":9,
"Adrar":1,
"Bejaia":6
}
print(dict1)
#in deep learning
import numpy as np
settings={
"W1": np.random.randn(1,20),
"b1":np.random.rand(13,16),
"W1":np.random.rand(20,1),
"b2":np.random.rand(1,16),
}
#to get the values
print(dict1.values())
#to get the keys
print(dict1.keys())
#to get the lenght
print("the lenght of my dict is:",len(dict1))
# to add an element
dict1["tizi-ouzou"]=15
print(dict1)
#get method
print(dict1.get("constantine")) #the value doesnt exist
print(dict1.get("Alger")) #output 16
#fromkeys method
list1=("banana","water","tomato","kiwi","oil")
print(dict1.fromkeys(list1,"test"))
value= dict1.pop('Bejaia')
print(value)
print("======")
#print all the values
for i in dict1.values():
print(i)
print("======")
# print the keys and values
for i,j in dict1.items():
print(i,j)
print("======")
#dict comprehension
dict1={
'0':'frameworks',
'1':'python',
'2':'django',
'3':'ai'
}
name=['frameworks','python','django','ai']
dico={k:v for k,v in enumerate(name)}
print(dico)
print(dico.keys())
print(dico.values())