-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDictionary 3 [adding list].py
More file actions
49 lines (37 loc) · 1.2 KB
/
Dictionary 3 [adding list].py
File metadata and controls
49 lines (37 loc) · 1.2 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
#;==========================================
#; Title: Python Dictionary 3
#; Author: @AyemunHossain
#;==========================================
#Adding a list in a dictionary
order={1:'Carrots',2:['Onion','Ginger','Potato']}
print(order)
student_info = {'name':['Ayemun','Hossain'],'id':1408,"cgpa":[3.33,3.45,4.00,3.44,3.56,2.52]}
print(student_info)
#Print these items
for key,items in student_info.items():
if type(items) == list:
print(f"{key} :",end='')
for i in items:
print(i,end=', ')
print('')
else:
print(f"{key} : {items}")
#Add new item in DICTIONARY
student_info["semester"]=['Spring-2019','Summer-2019','Fall-2019','Spring-2020']
#printing dict again
for key,items in student_info.items():
if type(items) == list:
print(f"{key} :",end='')
for i in items:
print(i,end=', ')
print('')
else:
print(f"{key} : {items}")
#Access the key list:
print(f"The First semester is : {student_info['semester'][0]}")
#Check the dictionary if it contain a certain key: return true if found
print('name' in student_info)
print('address' in student_info)
#let's check any value contains in dictionary value
print(1408 in student_info.values())
print('Ashik' in student_info.values())