Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

on Duu U2J* VERSU MU UVUVI SU IUS 120 pts) Write the method translate(translation Dict, txt) that takes in a dictionary and a string. The

image text in transcribed

on Duu U2J* VERSU MU UVUVI SU IUS 120 pts) Write the method translate(translation Dict, txt) that takes in a dictionary and a string. The dictionary contains keys of strings that have a value of another string. You will be translating the input string using the key-value pairs in the dictionary to a new string that has replaced all the words in the input string with the words' value in the dictionary. Your function should convert txt! to all lowercase letters and remove punctuation before making the translations. If a word in the string is not in the translation dictionary, the word will retain its original form. You can assume that all the keys in the dictionary are lowercase strings. Hint: str.lower() method returns a new string with all lowercase letters, str.split() splits a string into a list, default separator is any whitespace, and str.isalnum() returns True if all characters in a string are alphanumeric. Example: >>> myDict = {'up': 'down', 'down': 'up', 'left': 'right', 'right': 'left', '1': 'one'} >>> text = 'UP down left right forward 1 time! >>>translate(myDict, text) down up right left forward one time! itine intacar and The

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

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

0764532545, 978-0764532542

More Books

Students also viewed these Databases questions

Question

Discuss consumer-driven health plans.

Answered: 1 week ago