Page 1 of 1

Submit o Unit tests main.py do o E Console Shell Instructions D Run tests I Instructions 01 02 You are given two synonym

Posted: Fri May 20, 2022 10:45 am
by answerhappygod
Submit O Unit Tests Main Py Do O E Console Shell Instructions D Run Tests I Instructions 01 02 You Are Given Two Synonym 1
Submit O Unit Tests Main Py Do O E Console Shell Instructions D Run Tests I Instructions 01 02 You Are Given Two Synonym 1 (275.97 KiB) Viewed 43 times
it is not running the test case
Submit o Unit tests main.py do o E Console Shell Instructions D Run tests I Instructions 01 02 You are given two synonym dictionary files parse through each file line by line and retrieve the data each line will be a word with its synonyms in this format aa OD responsibility authority, control, leadership 1 def file_to_dict(filename): 2 3 dictionary = {} 4 file = open(filename, 'r') 5 lines = file readlines 6 Ist=[] 7 8 fon i in lines: 9 1 =1.replace("-", ") 10 1 Ureplace(" 11 1=uureplace("" 12 Ist append(i) 13 14 for line in ist: 15 tmplst = line.split(',') 16 key = tmplst[@] del (tmplst[0]) 18 value = tmplst 19 dictionary[key]=value; alue; 20 return dictionary 21 22 det main() 23 filename = input() 24 print(file_to_dict(filename) 25 26 y if _name=main" 27 main() your task is to form a dictionary which looks like the below one d = {"responsibility": ["authority", "control", "Leadership"]} Hint: 1. Read the file line by line as strings into a list ist 2. Replace space and with and 'in' with nothing 3. Take the ith string from the list 1st and split them as templst 4. make the oth them of templst as key and remaining as list of values 5. Do the 4th step by going through the other terms of templst and appending them into the dictionary key 6. Repeate the steps 3 and 5 until the len of Istte Windows Go to Set