Page 379 - Computer Science Class 11 With Functions
P. 379
42 for key in thesaurus.keys():
43 if word in thesaurus[key]:
44 synonyms.update(set(thesaurus[key]), {key})
45 elif key == word:
46 synonyms.update(set(thesaurus[key]))
47 if synonyms == set():
48 print('No synonyms found')
49 print('Want to add', word, ' to thesaurus?,Reply Y/y of N/n?')
50 addSynonym = input()
51 if addSynonym in ['Y','y']:
52 synonyms = eval(input('Enter synonyms as a tuple'))
53 thesaurus[word] = synonyms
54 else:
55 print('synonyms of ', word, ':', synonyms)
56
57 moreWords = input('Do you want synonyms of a word,Reply Y/y of N/n?')
58
59
60 #main segment
61
62 engDict()
Sample output:
Want to add more word and synonyms?(Y/y):n
beautiful ('alluring', 'delightful', 'charming', 'pleasing', 'attractive')
lovely ('cute', 'dazzling')
pretty ('nice-looking', 'beautiful')
Do you want synonyms of a word,Reply Y/y of N/n?y
>>> Enter a word:furious
No synonyms found
Want to add furious to thesaurus?,Reply Y/y of N/n?
y
>>> Enter synonyms as a tuple('angry', 'wild', 'stormy')
Do you want synonyms of a word,Reply Y/y of N/n?y
>>> Enter a word:irate
No synonyms found
Want to add irate to thesaurus?,Reply Y/y of N/n?
y
>>> Enter synonyms as a tuple('boiling', 'furious', 'heated')
Do you want synonyms of a word,Reply Y/y of N/n?y
>>> Enter a word:furious
synonyms of furious : {'angry', 'furious', 'irate', 'boiling', 'wild', 'stormy', 'heated'}
Do you want synonyms of a word,Reply Y/y of N/n?y
>>> Enter a word:heated
synonyms of heated : {'furious', 'irate', 'boiling', 'heated'}
Do you want synonyms of a word,Reply Y/y of N/n?
Solved Programming Questions
1. Write a function wordCountDict(lst)to find the number of occurrences of each word in a list of words in the
form of a dictionary. Apply the function wordCountDict(lst)to a list entered by the user.
01 def wordCountDict(lst):
02 '''
03 Objective: To find word frequency of words in a list.
04 Input Parameter: lst - list containing words
05 Return Value: Dictionary of words and their frequencies
06 '''
07 '''
Dictionaries 377

