Hey guys I need help with this question with 3 sub-problems.
NOTE: I Hope the below solution meets your requirements as per the Question. Please Do UPVOTE if it Does. :)
All test cases of the question are being checked and shown in below screenshots.
## Python Code:
## Part 1 of the problem
print()
print('-'*10,'PART 1 OF THE PROBLEM','-'*10)
print()
## Function to remove the short synonyms
def remove_short_synonyms(synonyms_dict):
# Iterating each key,value pair in the dictionary
for key,value in synonyms_dict.items():
# Empty list to store the new values for the key
new_value = []
# checking the lenght of the words in the value
for word in value:
if len(word) >= 8:
new_value.append(word)
synonyms_dict[key] = new_value
# returning the dictionary
return synonyms_dict
## Function to print the dictionary in sorted order
def print_dict_in_key_order(synonyms_dict):
for key,value in sorted(synonyms_dict.items()):
print(key,':',sorted(value))
# Storing the words with their synonyms in the form of
dictionary
synonyms_dict = {'look' : ['gaze', 'see', 'glance', 'watch',
'persue'],
'put' : ['place', 'set', 'attach', 'keep', 'save', 'set aside',
'achieve', 'do', 'build'],
'beautiful' : ['pretty', 'lovely', 'handsome', 'dazzling',
'splendid', 'magnificient'],
'slow' : ['unhurried', 'gradual', 'leisurely', 'late', 'behind',
'tedious', 'slack'],
'dangerous' : ['perilous', 'hazardous', 'uncertain']
}
# Removing the short synonyms from the dictionary
synonyms_dict = remove_short_synonyms(synonyms_dict)
print('1.')
# printing the dictionary
print_dict_in_key_order(synonyms_dict)
print()
# Storing the words with their synonyms in the form of
dictionary
synonyms_dict = {'come' : ['approach', 'advance', 'near', 'arrive',
'reach'],
'show' : ['display', 'exhibit', 'present', 'note', 'point to',
'indicate', 'explain', 'reveal', 'prove', 'demonstrate',
'expose'],
'good' : ['excellent', 'fine', 'superior', 'wonderful', 'grand',
'superb', 'edifying'],
'bad' : ['evil', 'immoral', 'wicked', 'rotten', 'contaminated',
'spoiled', 'defective', 'substandard', 'faulty', 'improper',
'inappropriate']
}
# Removing the short synonyms from the dictionary
synonyms_dict = remove_short_synonyms(synonyms_dict)
print('2.')
# printing the dictionary
print_dict_in_key_order(synonyms_dict)
print()
print()
## Part 2 of the problem
print()
print('-'*10,'PART 2 OF THE PROBLEM','-'*10)
print()
# Function to check the donditions of dict1 and dict2
def contains_keys_and_values(dict1, dict2):
# If any of the condition fails return False else return True
# checking if dict1 contains all the keys of dict2
for key in dict2.keys():
if key not in dict1.keys():
return False
dict1_values = []
# checking if the values of dict2 is in any corresponding value
list in dict1
for value in dict1.values():
dict1_values.extend(value)
for value in dict2.values():
for ele in value:
if ele not in dict1_values:
return False
# if both the condition is satisfied return True
return True
# Checking the working of the contains_keys_and_values function
for different set of values
dict1 = {}
dict2 = {}
print('1.', contains_keys_and_values(dict1, dict2))
dict1 = {'a': [4,3] , 'd' : [6,2], 'z':[], 't': [2,23]}
dict2 = {'z': [2,3,6,23], 'a':[4]}
print('2.', contains_keys_and_values(dict1, dict2))
dict1 = {'a': [6,3], 'p':[]}
dict2 = {'a': [3,6,3], 'p':[6,1]}
print('3.', contains_keys_and_values(dict1, dict2))
dict1 = {'a': [6,3], 'p': []}
dict2 = {'a': [3,6,3], 'p': ['a']}
print('4.', contains_keys_and_values(dict1, dict2))
dict1 = {'a': [6,3], 'p': ['a'], 't': ['s']}
dict2 = {'a': [3,6,3], 'p':['a'], 's': ['a']}
print('5.', contains_keys_and_values(dict1, dict2))
## Part 3 of the problem
print()
print('-'*10,'PART 3 OF THE PROBLEM','-'*10)
print()
# Function to get the previous words of the dictionary
def get_previous_words_dict(text):
# converting the text into list
text = text.split()
# creating an empty dictionary to store the unique words with value
as previous words
previous_words_dict = {}
# getting the unique words from the text in the sorted order
keys = sorted(set(text))
# iterating through each key
for key in keys:
# Empty list to store the previous words
previous_words = []
# finding the prevous words for the key
for index in range(len(text)):
if key == text[index]:
if index == 0:
previous_words.append('')
else:
previous_words.append(text[index-1])
# adding the key with previous words list to the dictionary
previous_words_dict[key] = previous_words
# returning the dictinoary
return previous_words_dict
# Checking the working of get_previous_words_dict function for
different values
sentence = 'a man we saw saw a saw'
previous_words_dict = get_previous_words_dict(sentence)
print_dict_in_key_order(previous_words_dict)
print()
sentence = 'my favourite painting is the painting i did of my
dog in that painting in my den'
previous_words_dict = get_previous_words_dict(sentence)
print_dict_in_key_order(previous_words_dict)
## Screenshots of the Code in IDLE:
## Screenshots of the Output:
Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti s...
Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can be solved in one post so I posted the other on another question so please check them out as well :) Here is the questions in this assignment: Note: Two helper functions Some of the testing codes for the functions in this assignment makes use of the print_dict in_key_order (a dict) function which prints dictionary keyvalue pairs...
Hey guys I need help with this question: # 4444444444444444444444444444444444444444444444444 # get-triples-dict() Define the get triples diet) funetion which is passed a string of text as a The function first converts the parameter string to lower case turns a dictionary with keys which are all the unique consecutive tic characters from the text, and the corresponding values are characters appear in parameter. and then re three alphabe the number of times the three consecutive alphabetic text. Use the isalpha() method...
PYTHON Define the remove_e_synonyms() function which is passed a dictionary as a parameter. The keys of the parameter dictionary are words and the corresponding values are lists of synonyms (synonyms are words which have the same or nearly the same meaning). The function removes all the synonyms which contain the letter 'e' or 'E') from each corresponding list of synonyms. As well, the function sorts each corresponding list of synonyms. Note: the testing code makes use of the print_dict_in_key_order(a_dict) which...
Help me with this Python Question a. build_word_dictionary (filename) – This builds a word dictionary indexed by words from the file who’s filename is provided as an argument. It uses the words as keys and the count of occurrences as values. It returns the dictionary it constructed. It can use the ‘tokenize()’ function that is provided in the lecture slides. b. inverse_dict(dict) – This method takes a dictionary (generated by build_word_dictionary() and inverts it (as was done with students and...
# 1111111111111111111111111111111111111111111111111 # draw_histogram() #-------------------------------------------------- #-------------------------------------------------- """ Define the draw_histogram() function which is passed a Python dictionary as a parameter. The keys of the dictionary are single letters and the corresponding values are integers, e.g., {'b': 5, 'a': 6, 'c': 3}. For each key:value pair in the dictionary the function prints the key, followed by ": ", followed by a series of stars. The number of stars printed is given by the value corresponding to the key. The keys are...
python please 11 def add_item(items, word): 14 15 16 F # check if the word is in the dictionary (keys of dictionary) if word in items: items [word] = items (word] + 1 # update the count else: # word is not in dictionary items[word] = 1 # add the word with count 1 return items [word] # return the current count of word after updation Create a function named build_dictionary that takes a list of words (as a parameter)...
I need help writing these : Given a dictionary gradeCounts = { "A": 8, "D": 3, "B": 15, "F": 2, "C": 6} write the Python statement(s) to print: a. all the keys. b. all the values. c. all the key and value pairs. d. all of the key and value pairs in key order. e. the average value. f. a chart similar to the following in which each row contains a key followed by a number of asterisks equal to...
Hey I have a task which consists of two part. Part A asks for writing a program of WORD & LINE CONCORDANCE APPLICATION in python which I have completed it. Now the second part has given 5 dictionary implementation codes namely as: (ChainingDict, OpenAddrHashDict with linear probing, OpenAddrHashDict with quadratic probing, and 2 tree-based dictionaries from lab 12 (BST-based dictionary implementation) and asks for my above program WORD & LINE CONCORDANCE APPLICATION to use these implemented code and show the time...
I need help in C++ implementing binary search tree. I have the .h file for the binary search tree class. I have 4 classic texts, and 2 different dictionaries. Classic Texts: Alice In Wonderland.txt A Tale of Two Cities.txt Pride And Prejudice.txt War and Peace.txt 2 different dictionaries: Dictionary.txt Dictionary-brit.txt The data structures from the standard template library can not be used.The main program should open the text file, read in the words, remove the punctuation and change all the...
I need help for this assignment. Thank you!! # 5555555555555555555555555555555555555555555555555 # Returns the longest word (which has six or more # characters and contains the letter, e) from # the parameter list - 4 marks Os Define the get_longest_e_word() function which is passed a list of strings as a parameter. The function returns the word in the list which has the most characters (i.e., the longest word) BUT only words which have 6 or more characters and contain the letter...