Answered step by step
Verified Expert Solution
Link Copied!

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!

image text in transcribed

image text in transcribed

#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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

Students also viewed these Databases questions

Question

Define and measure service productivity.

Answered: 1 week ago