Repository navigation
Expand file tree
/
Copy pathPython_Dictionary_Basic_Practice
More file actions
69 lines (42 loc) · 1.74 KB
/
Copy pathPython_Dictionary_Basic_Practice
File metadata and controls
69 lines (42 loc) · 1.74 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
#Python_Dictionary_Basic_Practice
#Create an empty dictionary
Employyes={}
Employees={'Jack':{'Last name':'Morgan','salary':1200,'Age':22},\
'Lucy':{'Last name':'lindy','salary':5400,'Age':30},\
'Miranda':{'Last name':'Blung','salary':8200,'Age':48}
}
#Access values in a dictionary
EmployeeNumber1=Employees['Jack']
EmployeeNumber2=Employees['Lucy']
EmployeeNumber2=Employees['Lucy']
#Print a dictionary
print(Employees)
print('------------------------------------------------------------\n\n')
print(EmployeeNumber2)
print('------------------------------------------------------------\n\n')
#Find the length of the dictionary
len(Employees)
print("The length of the Employees dictionary is ",len(Employees))
print('------------------------------------------------------------\n\n')
#Insert an entry in the dictionary
Employees={'Jack':{'Last name':'Morgan','salary':1200,'Age':22},\
'Lucy':{'Last name':'lindy','salary':5400,'Age':30},\
'Miranda':{'Last name':'Blung','salary':8200,'Age':48}
}
Employees['James']={'Last name':'Clark','salary':3400,'Age':40,'Position': 'Clerk'}
print(Employees)
print('------------------------------------------------------------\n\n')
#Delete an entry from the dictionary
del EmployeeNumber2['Age']
print(EmployeeNumber2)
print('------------------------------------------------------------\n\n')
#Get all the entries from the dictionary
myList = Employees.items()
for x in myList:
print(x)
print('------------------------------------------------------------\n\n')
#Get all keys from the dictionary
myList = Employees.keys()
for x in myList:
print(Employees.get(x))
print('------------------------------------------------------------\n\n')