Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Answer in python codeblock! For this question, we will utilize a list of words provided by the NLTK (Natural Language Toolkit) library. We will

Please Answer in python codeblock!

For this question, we will utilize a list of words provided by the NLTK (Natural Language Toolkit) library. We will likely use NLTK more later in the quarter, but for now start by simply running the code below to get a list of English words. Keep in mind that this is not necessarily a complete list of English words (e.g. "carousel" is not in the list), but it suffices for this question.

import nltk nltk.download('words')

from nltk.corpus import words

# You can refer to word_lst for checking if a string is a valid English word word_lst = words.words()

Write a function called word_sandwich that takes two strings as input, call them str_a and str_b.

Since this question is more interesting if the input strings are valid words, the function should first determine if str_a and str_b are in fact English words. If they are not, return None. Otherwise, continue on.

The function should determine if by inserting str_a somewhere inside str_b or by inserting str_b somewhere inside str_a, a new word can be formed. That is, we want to know if the words can "meld". You should create an inner function that checks one direction (like str_a into str_b) to prevent repeating code.

Here are a few example inputs and outputs:

Input: ("eight", "yes"), Output: "eyesight" Input: ("net", "magic"), Output: "magnetic" Input: ("entry", "eat"), Output: "entreaty" Input: ("word", "sandwich"), Output: None Input: ("i", "team"), Output: None Input: ("butter", "fly"), Output: None

Note that we are not checking if the two words concatenated form another word. We are interested in checking if by inserting one word inside another (not at the front nor at the end) we can form a new word.

Test your program by trying out the above word pairs as examples. If you can think of more valid words sandwiches, feel free to use them.

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago