Write a python 3 function named words_in_both that takes two strings as parameters and returns a set of only those words that appear 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".
1.Use python's set intersection operator in your code.
2.Use Python's split() function, 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 is a jack of all trades", 'Jack was tallest of all')

Answers

Answer 1

Answer:

def words_in_both(a, b):

 a1 = set(a.lower().split())

 b1 = set(b.lower().split())

 return a1.intersection(b1)

common_words = words_in_both("She is a jack of all trades", 'Jack was tallest of all')

print(common_words)

Explanation:

Output:

{'all', 'of', 'jack'}

Answer 2

The program returns the words which exists in both string parameters passed into the function. The program is written in python 3 thus :

def words_in_both(a, b):

#initialize a function which takes in 2 parameters

a1 = set(a.lower().split())

#split the stings based on white spaces and convert to lower case

b1 = set(b.lower().split())

return a1.intersection(b1)

#using the intersection function, take strings common to both variables

common_words = words_in_both("She is a jack of all trades", 'Jack was tallest of all')

print(common_words)

A sample run of the program is given thus :

Learn more : https://brainly.com/question/21740226

Write A Python 3 Function Named Words_in_both That Takes Two Strings As Parameters And Returns A Set

Related Questions

Write a program that calculates the area & perimeter of a rectangle, where
the values for width and length are given by the users.

Answers

Answer:

In Python:

Length = float(input("Length: "))

Width = float(input("Width: "))

Area = Length * Width

Perimeter = 2*(Length + Width)

print(Area)

print(Perimeter)

Explanation:

This gets the length from the user

Length = float(input("Length: "))

This gets the width from the user

Width = float(input("Width: "))

This calculates the area

Area = Length * Width

This calculates the perimeter

Perimeter = 2*(Length + Width)

This prints the area

print(Area)

This prints the perimeter

print(Perimeter)

Classify the characteristics as abstract classes or interfaces.

A. Uses the implements keyboard
B. Cannot have subclasses
C. Does not allow static and final variables
D. Can have subclasses
E. Uses the extends keyboard
F. Allows static and final variables

Answers

E for eeeedeerreeeee

How does the pay for many Science, Technology, Engineering, and Mathematics workers compare to the overall median for all careers? It is far lower than the overall median. It is far higher than the overall median. It is slightly higher than the overall median. It is about the same as the overall median.

Answers

Answer:

B

Explanation:

It just is

Answer:

B is correct

Explanation:

What infection type can send information on how you use your computer to a third party without you realizing it

Answers

Answer:

Spyware collects your personal information and passes it on to interested third parties without your knowledge or consent. they also install trojan horses

Explanation:

CH4 has how many of each type of atom?

Answers

Its easy that moderators that see this answer can think that my answer isn't without explanation.

• Type of atom C (Carbon)

C = 1

• Type of atom H (Hydrogen)

H = 4

You dont understand? JUST SEE THE FORMULA C MEANS ONLY HAVE 1 CARBON ATOM AND H4 MEANS 4 ATOM OF HYDROGEN

oK. have a nice day hope you understands

How do I fix a phone if I don't have enough money for me to fix it?

Answers

Answer:

depends whats wrong with it

Explanation:

is the screen smashed orr~

______ are special characters that allow you to
search for multiple words at the same time.
-Find expressions
-Defined expressions
-Regular expressions
-Search expressions

Answers

Answer:

Defined Expression

Explanation:

This will be your answer

Your computer system looses power while you are working on a project for a very important client

Answers

isljgaek jadkghdkjhasdkjfhadskj afhdsfkjdahk dh

Answer:

I never knew that, thank you for telling me! I'll note that down

What is the influence of new technology on society?
Ο Α. .
New technology hardly has any impact on society.
OB.
New technology is only beneficial to society and cannot be detrimental.
OC.
New technology is detrimental, as it makes the existing technology obsolete.
OD. New technology normally utilizes a lot of resources and can adversely affect the economy.
O E.
New technology is beneficial but can also be usedly a detrimental way.

Answers

Answer:

E. New technology is beneficial but can also be used in a detrimental way.

Explanation:

New technology such as cryptocurrency (powered by blockchain technology) can be regarded as a welcome development that has benefited the society in so many good ways. However, cryptocurrency as a new technology also has disadvantages it presents to the society. One of such negative influence cryptocurrency has is that it can be used for illicit activities such as money laundering, funding terrorism and so on.

So, in summary, we can conclude that:

"New technology is beneficial but can also be used in a detrimental way."

ANSWER QUICK 50 POINTS
You have the following code in your program.

from array import *
Which line of code would create an array?


D = array([2.5, 3, 7.4])

D = array('f',[2.5, 3, 7.4])

D = array['f',[2.5, 3, 7.4]]

D = array('f',2.5, 3, 7.4)

Answers

Answer:

D = array('f',[2.5, 3, 7.4])

Explanation:

is the answer

A variable must be declared with an array type before the array itself can be created. Array types resemble other Java types, with the exception that square brackets are placed after them ( [] ). Thus, option D is correct.

What line of code would create an array?

Using the NumPy library, new data types known as arrays can be produced in Python. NumPy arrays are created for numerical studies and only contain one data type.To build an array, use the array() method after importing NumPy. The input for the array() function is a list.

An array, also known as a database system, is a group of things or data that is held in a contiguous memory area in coding and programming. Several instances of the same kind of data are grouped together in an array.

Therefore, D = array('f',2.5, 3, 7.4)  line of code would create an array.

Learn more about array here:

https://brainly.com/question/22296007

#SPJ2

Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:
As long as x is greater than 0
Output x % 2 (remainder is either 0 or 1)
x = x // 2
Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string.
Ex: If the input is:
6
the output is:
110
Your program must define and call the following two functions. The function integer_to_reverse_binary() should return a string of 1's and 0's representing the integer in binary (in reverse). The function reverse_string() should return a string representing the input string in reverse.
def integer_to_reverse_binary(integer_value)
def reverse_string(input_string)
Note: This is a lab from a previous chapter that now requires the use of a function.

Answers

Answer:

#include <iostream>//header file

#include <string>//header file

using namespace std;

string integer_to_reverse_binary(int integer_value)//defining a method integer_to_reverse_binary  

{

   string ret = "";//defining string variable

   while (integer_value > 0) //using while loop to check integer_value value is greater than 0

   {

       ret += '0' + (integer_value % 2);//adding zeros in remainder value

       integer_value /= 2;//holding quotient value

   }

   return ret;//return string value

}

string reverse_string(string input_string)//defining a method reverse_string that holds a parameter user_String  

{

   string result;//defining a string variable  

   for (int i = 0; i < input_string.length(); ++i)//use for loop to calculate value  

   {

       result += input_string[input_string.length()-i-1];//add value in result variable

   }

   return result;//result result variable value

}

int main()//defining main method  

{

   int num;//defining integer variable

   string str;//defining string variable

   cin >> num;//input num value

   str = integer_to_reverse_binary(num);//use str variable to call the integer_to_reverse_binary method

   cout << reverse_string(str) << endl;//printing the reverse_string method value

   return 0;

}

Output:

6

110

Explanation:

In this code two string method "integer_to_reverse_binary and reverse_string" is defined that holds one parameter "integer_value and input_string".

In the first method a string variable is defined, that use the while loop to check integer value is greater than 0 and add zeros in the value and return its value as a string.

In the second it reverse the string value and store into the result variable, and in the main method the "num and str" variable is defined, and in the num it takes integer value and pass into the above method and print its return value.    

Other Questions
An informative essay shouldA.)be entertaining and interesting.B.)explain why something happened.C.)argue as well as make a point.B.)result from extensive research. An item has a listed price of 35$ if the sales tax rate is 3% how much is the sales tax in dollars Find the 53rd term of the arithmetic sequence -12,-1,10 What would it have been like to be a child in an industrial city ? Analyze the map below and answer the question that follows.Image courtesy of NASAWhat is the name of the country located at number 2 on the map above?A.BrazilB.VenezuelaC.ColombiaD.ArgentinaPlease select the best answer from the choices providedABCD What is the quotient and remainder of 55 divided by 4 How does Lady Macbeth cover for Macbeth at the banquet?A. She says that hes behaved this way since he was young.B. She changes the subject to blaming Malcolm and Donalbain.C. She plays along, as if Macbeth was acting out a scene from a play.D. She faints. Which set(s) of side lengths could not be used to construct a triangle? List three types of factors that influence weight status I need help plz Describe the Vocal Music and instrumental music of Visayas Which triangle is a 30-60-90 triangle?10O5,31555/510510/315105./3 Any Netflix suggestions to watch? How many grams are there in 13 kilograms? Match the following to its correct meaning. If a/band c/dare rational expressions, then a/b*c/d=a*d/b*c. A. TrueB. False What was a result of the changing economy of the North during the mid- 1800s?A. More people in the North became craftspeople making goods by hand. B. More people in the North became plantation workers.C. More people in the North found jobs as factory workers.D. More people in the North moved out of cities to the country. Bobby is 5 less than Kylie's age. Their combinedage is 43. How old is Kylie? HELP HELP HELP 5TH GRADE MATHILL MARK BRAINLIEST 1. Why is there tension between John and Elizabeth Proctor?A. The family farm is not doing well because the crops are dying.B. John thinks Elizabeth will not forgive him for his affair with AbigailC. Abigail keeps stopping by their house to ask for John.D. Elizabeth has been sick for several weeks and has done no chores.