forked from amirkhan1092/python38-GLA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdict_example.py
More file actions
52 lines (35 loc) · 1.05 KB
/
Copy pathdict_example.py
File metadata and controls
52 lines (35 loc) · 1.05 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
# dictionary creation empty
d = {}
print(d, type(d)) # {} <class 'dict'>
d = dict() # dict constructor
print(d, type(d)) # {} <class 'dict'>
# dictionary operation
dct = { 'rolln':30, 'cpi':8.0, 'section':'A', 'name':'akshay'}
print(dct, type(dct))
# accessing the element
d = dct['name'] # element at given key
print(d)
# keys() : get all the keys of dict
dct = {'name':'Govind', 'rolln':30, 'cpi':7.0, 'section':'E'}
out1 = dct.keys()
print(out1) # dict_keys(['name', 'rolln', 'cpi', 'section'])
out2 = dct.values()
print(out2, type(out2)) # dict_values(['Govind', 30, 7.0, 'E']) <class 'dict_values'>
# update value at key
dct = {'name':'Govind', 'rolln':30, 'cpi':7.0, 'section':'E'}
dct['name'] = 'Akshay'
dct['adress'] = 'GLA Mathura'
print(dct)
d = {'car':['alto', 'nano'], 'color':'white', 'model':1990,
'speed':70, 23:'its number', (2, 4):'its tuple', 'car':'santro'}
print(d)
k = '1234*23)-87K81.2e'
ls = []
u = ''
for i in k:
if i.isdigit() or i == '-' or i == '.':
u += i
else:
ls.append(u)
u = ''
print(ls)