1.
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 printed in alphabetical order. Note that the key is not printed if the corresponding value is a number less than 1.
For example, the following code:
print("1.")
draw_histogram({'a': 2, 'c': 7, 'b': 5})
print()
print("2.")
draw_histogram({'a': 0, 'c': 5, 'b': 7, 'f': 0})
prints the following:
1.
a: **
b: *****
c: *******
2.
b: *******
c: *****
2.
Define the get_last_three_letters_dict() function which is passed a string of text as a parameter. The function first converts the parameter string to lower case and then returns a dictionary object which has:
• keys which are the last three letters of any words in the parameter string of text with length greater than 2, and,
• corresponding values which are the number of words in the parameter string of text which end with these last three letters.
Notes:
• the testing code removes any pairs in the resulting dictionary where the last three letters occur just the once in the parameter string of text.
• the testing code makes use of the print_dict_in_key_order(a_dict) which prints the dictionary pairs in sorted key order.
For example, the code:
text = ' "west best worst first tapping snapping in a pest the straining singing forest living'
a_dict = get_last_three_letters_dict(text)
remove_less_than_2(a_dict)
print("1.")
print_dict_in_key_order(a_dict)
print()
text = 'Kublai Khan does not necessarily believe everything Marco Polo says when he describes the cities visited on his expeditions but the emperor of the Tartars does continue listening to the young Venetian with greater attention and curiosity than he shows any other messenger or explorer of his'
a_dict = get_last_three_letters_dict(text)
remove_less_than_2(a_dict)
print("2.")
print_dict_in_key_order(a_dict)
prints:
1.
est : 4
ing : 5
rst : 2
2.
han : 2
his : 2
ing : 2
oes : 2
the : 4
def draw_histogram(data):
s = "" # to store the result
#use sorted() to sort dictionary by keys
#loop through all the keys in the dictionary
for x in sorted(data) :
#store the keys first if freq is non 0
if(data[x] > 0):
s = s + str(x) + ": "
#store the required number of *
for i in range(data[x]):
s = s + "*"
#Add new line
s = s + " "
#print all data
print(s)
return
print("1.")
draw_histogram({'a': 2, 'c': 7, 'b': 5})
print()
print("2.")
draw_histogram({'a': 0, 'c': 5, 'b': 7, 'f': 0})

1. Define the draw_histogram() function which is passed a Python dictionary as a parameter. The keys...
# 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
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...
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...
in Python, define a function named filterOut with three parameters. The first argument passed to the function should be a list of dictionaries (the data), the second a string (a dictionary key), and the third another string (a dictionary value). This function must return a list of all the dictionaries from the input list which do NOT contain the indicated key:value pairing. in Python, define a function named filterInRange with four parameters. The first argument passed to the function should...
python Define a function called print_values which takes a dictionary object as a parameter. The function should print all values in the dictionary. However, the order is based on the sorted keys in the dictionary. For example, if we have the following dictionary: {'b':36, 'a':12, 'c':24} The output is: 12 36 24 A faulty solution has been provided below. Identify the fault and submit a corrected version of this code. def print_values(dict1): for k in list(dict1.keys()).sort(): print(dict1[k], end=" ") For...
Basic Python code needed
Define the get_lines_from_file) function which is passed a filename as a parameter. The function reads the information from the file (corresponding to the filename parameter) and returns a list of strings where each element of the returned list corresponds to one line of the file. The list of strings which is returned by the function should not contain any newline characters. For example, if the file contains the text: 10 440 240 4 42 4 42...
Hey guys I need help with this question with 3 sub-problems.
f test remove short synonyms () Define the remove shorti synonyms function which is passed a dictionary as a parameter- The keys of the parameter dictionary are words and the corresponding values are 1ists of synonyms (synonyms are words which have the same or nearly the same meaning). The function romoves all the eynonyme which have ous than 8 charactors from each corresponding list of synonyms-As well, the funet...
This script will create a dictionary whose keys are all the directories listed in thePATH system variable, and whose values are the number of files in each of these directories. The script will also print each directory entry sorted by directory name. The script will use the following five functions to get the required results get_environment_variable_value() get_dirs_from_path() get_file_count() get_file_count_for_dir_list() print_sorted_dictionary() get_environment_variable_value() The header for this function must be This function must accept a shell variable as its only parameter The...
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 5. Write a function named grade_components that has one parameter, a dictionary. The keys for the dictionary are strings and the values are lists of numbers. The function should create a new dictionary where the keys are the same strings as the original dictionary and the values are tuples. The first entry in each tuple should be the weighted average of the non-negative values in the list (where the weight was the number in the 0 position of the...