Question 4
Question 4
def create():
f=open('myfile.txt','w')
Output
s=input('enter string: ') main menu-
d[i]=s.count(i) enter string: hello hello hi hi how are you hope you are are
correct
print('the histrogram is: ')
the histrogram is: do you want to continue: y
print(d)
{'hello': 2, 'hi': 2, 'how': 1, 'are': 3, 'you': 2, 'hope': 1,
return(d) 'correct': 1}
1.create histogram:
l.append(d[i])
main menu-
f=open('myfile.txt','r') {5: ['hello', 'hello'], 2: ['hi', 'hi'], 3: ['how', 'are', 'you', 'you',
'are', 'are'], 4: ['hope'], 7: ['correct']}
d={}
do you want to continue: y
s=f.read()
main menu-
o=s.split()
1.create histogram:
temp=s.split()
2.to do various function on histogram:
for i in temp:
3.create a dictionary containing length greater than
l=[]
specified character length:
for j in o:
4.to find the longest word:
a=len(i)
5. words having length greater than specified character
b=len(j) length:
l.append(j) {5: ['hello', 'hello'], 2: ['hi', 'hi'], 3: ['how', 'are', 'you', 'you',
'are', 'are'], 4: ['hope'], 7: ['correct']}
d[a]=l
The longest word is: ['correct']
print(d)
do you want to continue: y
return(d)
main menu-
f.close()
1.create histogram:
print('The longest word is: ',l) The list of words having word length greater than 2 is:
d=lend()
l=[]
for i in d:
if len(d[i])>n:
l.append(d[i])
print('The list of words having word length greater than ',n,'is: ')
print(l)
ch='y'
while ch=='y':
print('3.create a dictionary containing length greater than specified character length: ')
print('5. words having length greater than specified character length: ')
if op==1:
create()
elif op==2:
dofunction(create())
elif op==3:
lend()
elif op==4:
findlongestword()
elif op==5:
listaccording()
else:
print('wrong option')
break