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:
EXPLANATION IN CODE COMMENTS :
def remove_less_than_2(dic):
all_keys = list(dic.keys())
for key in all_keys:
if dic[key]==1:
del dic[key]
return dic
def print_dic_in_key_order(dic):
#print dictionary content in sorted key order
for key in sorted(dic):
print(key ,":", dic[key])
print()
def draw_rows(dic):
#run two loops and print the value key times
for key in sorted(dic):
print(key ,":",end =" ")
for i in range(key):
print(dic[key],end ="")
print()
print()
def get_text_valuation(dic,text):
sumA=0
#loop over text , if character is alphabet and it exits in
dictionary then add value to sum
#else add 1 to the sum
for i in text.lower():
if i.isalpha()==True:
if i in dic.keys():
sumA+=dic[i]
else:
sumA+=1
return sumA
"""
33333333333333333333333333333333333333333333333333
"""
def get_word_len_dict(text):
l = text.split(" ")
dic = {}
#for each word in the list, get its length
#if len exists as key in dictionary , append the word to it
#else create a new entry in the dictionary
for i in l:
key = len(i)
if key in dic.keys():
if i not in dic[key]:
dic[key].append(i)
else:
dic[key]=[i]
for value in dic.values():
value.sort()
return dic
"""
444444444444444444444444444444444444444444444444444
"""
def get_triples(text):
dic = {}
s=""
#loop over text as lower() , take string as s
#in each iteration add each character if it is alphabet to s
#when length of s reaches 3, if it exists in the dictionary , add
one to it
#else create a new entry
for i in text.lower():
if i.isalpha() == True:
s += i
if len(s)==3:
if s in dic.keys():
dic[s]+=1
else:
dic[s]=1
s = s[1:]
#remove all the entries in the dictionary whose value is == 1
return remove_less_than_2(dic)
dic = {4:'a',7:'c',4:'b'}
draw_rows(dic)
dic = {"r":2,"s":2,"h":4,"t":3,"m":7,"g":4,"v":8}
letters = "BLAH"
print("1. ",letters," - ",get_text_valuation(dic,letters),"\n")
text = "May your coffee be strong and your monday be
short"
dic = get_word_len_dict(text)
print_dic_in_key_order(dic)
text = "super , duper"
print_dic_in_key_order(get_triples(text))
Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can...
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...
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...
# 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...
The skeleton code (starter file) for the problem is pasted below: def phoneNumber(letters): result = "" # ADD YOUR CODE HERE return result def loadEvents(filename): events = {} # ADD YOUR CODE HERE return events def timeline(events): # ADD YOUR CODE HERE return # DO NOT modify or remove the code below! We will use it for testing. if __name__ == "__main__": # Problem 1: Decoding Telephone Numbers ph = input("Enter the text to translate: ") print("The corresponding phone number...
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 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...
C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...
hello. i need help with number 2 ONLY 1. Use if statements to write a Java program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way 2=ABC 3 = DEF 4 GHI 5 JKL 6 - MNO 7 - PRS 8 - TUV 9-WXY No digit corresponds to either Qor Z. For these 2 letters your program should print a message indicating that they...
In python, PART A: I am trying to get a dictionary with size(4, 5, 6) as keys and an array for key containing a list of values (words from file of respective size) associated with those keys I am reading from a file of strings, where I am only interested with words of length 4, 5, and 6 to compute my program reading the text file line by line: At first, I have an empty dictionary then to that I...
Question #2 A DNA molecule can be specified using a string of the characters , ‘g 'a', 't'. Each of these characters represents one of the four nucleobases Cytosine, Guanine, Adenine, and Thymine. Consult the wikipedia page on DNA for more details. A codon consists of a sequence of three DNA nucle- obases and can be represented by a string of length 3 consisting of characters from the set ‘c', ‘g', ‘a", ‘t'. So "cga" and "ttg" are examples of...