Question
project-8b Write a function named words_in_both that takes two strings as parameters and returns a set of the words contained in both strings. You can
project-8b
Write a function named words_in_both that takes two strings as parameters and returns a set of the words contained in both strings. You can assume all characters are letters or spaces. Capitalization shouldn't matter: "to", "To", "tO", and "TO" should all count as the same word. The words in the set should be all lower-case. For example, if one string contains "To", and the other string contains "TO", then the set should contain "to".
You can use Python's split() funciton, which breaks up a string into a list of strings. For example:
sentence = 'Not the comfy chair!' print(sentence.split()) ['Not', 'the', 'comfy', 'chair!']
Here's one simple example of how words_in_both() might be used:
common_words = words_in_both('She's a jack of all trades', 'Jack was tallest of all')
The file must be named: words_in_both.py
code in python
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