Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can somebody fix my python code! I don't understand what's wrong with the code. Note the code has to output something similar to the second
Can somebody fix my python code! I don't understand what's wrong with the code. Note the code has to output something similar to the second picture. Thanks!
#open the text file and read it file_open = open ("Words2.txt", 'r') text_file_list file_open.readlines() text list [] for line in text_file_list: #taking away the indivual lines and making it into one big list text_list.extend(line.replace(" ','').split(',')) #outputing the words in the new list #here i have print below just to check my work along the way #print("Provided list...: ", text_file_list) #Creating new list that all words will be lowercase text_new =[] for word in text_list: if word is not None and word != ""; text_new.append(word. lower().strip) #output the new text list #here i have print below just to check my work along the way #print ( New lowercase list:' , text_new) #building the dictionary dictionary = {} #here we want to append the dictionary values for val in text_new: dictionary.setdefault(val[@],[]).append(val) #print('Creating Dictionary...', dictionary) #print("Dictionary in Alphabetical Order without Duplicates:") for key in dictionary.keys (): print(f'{val} - {set (sorted(dictionary[val])}.'.) #why is this invalid? Word List Lower Cases t'add", "hen Dict Conversion ('a' ('add', 'alpha Dictionary in Alphabetical Order with - {'at', 'add', 'alpha"} b. (both', 'out', "box") C ('cat', 'cow) d. 'dog' h - ("horse', 'hen") (man', 'monkey) #open the text file and read it file_open = open ("Words2.txt", 'r') text_file_list file_open.readlines() text list [] for line in text_file_list: #taking away the indivual lines and making it into one big list text_list.extend(line.replace(" ','').split(',')) #outputing the words in the new list #here i have print below just to check my work along the way #print("Provided list...: ", text_file_list) #Creating new list that all words will be lowercase text_new =[] for word in text_list: if word is not None and word != ""; text_new.append(word. lower().strip) #output the new text list #here i have print below just to check my work along the way #print ( New lowercase list:' , text_new) #building the dictionary dictionary = {} #here we want to append the dictionary values for val in text_new: dictionary.setdefault(val[@],[]).append(val) #print('Creating Dictionary...', dictionary) #print("Dictionary in Alphabetical Order without Duplicates:") for key in dictionary.keys (): print(f'{val} - {set (sorted(dictionary[val])}.'.) #why is this invalid? Word List Lower Cases t'add", "hen Dict Conversion ('a' ('add', 'alpha Dictionary in Alphabetical Order with - {'at', 'add', 'alpha"} b. (both', 'out', "box") C ('cat', 'cow) d. 'dog' h - ("horse', 'hen") (man', 'monkey)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started