Skip to content

Commit 532bd64

Browse files
authored
Update dictionary.py
1 parent aea752e commit 532bd64

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

dictionary.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,40 @@
5757
data = bio.get('interest','no such key-value pair is present')
5858
print(data)
5959
'''
60+
# Sorting in dictionary
61+
# Also, Dictionary and list together
62+
63+
f = {
64+
'bob':'python',
65+
'harry':'ruby',
66+
'jack':'c',
67+
'stan':'java',
68+
}
69+
70+
list1 = ['jack','stan']
71+
for each in f.keys():
72+
print(each.title())
73+
74+
if each in list1:
75+
print('hi ' + each.title()+' you said your fav lang is ' +f[each].title()+ '!')
76+
77+
note: that in last line the 'each' will work for 'values' as well, just mention it with dictionary name.
78+
You can also use the keys() method to find out if a particular person was polled.
79+
means if a person is not present in list we can send a message like,
80+
81+
if 'peter' not in f.keys():
82+
print('Peter please mention your fav language')
83+
84+
for every in sorted(f): # sorting in dictionary
85+
print('Thanks ' + every.title() + ' for taking the poll')
86+
87+
output:
88+
Thanks Bob for taking the poll
89+
Thanks Harry for taking the poll
90+
Thanks Jack for taking the poll
91+
Thanks Stan for taking the poll
92+
93+
6094
6195
# question 1: Introducion
6296
'''

0 commit comments

Comments
 (0)