Question: Write the about function, which takes a list of topic words. It returns a function that can be passed to the choose function as the
Write the "about" function, which takes a list of topic words. It returns a function that can be passed to the choose function as the select argument. The returned function takes a paragraph and returns a boolean indicating whether that paragraph contains any of the words in topic. To make this comparison accurately, you will need to ignore case (that is, assume that uppercase and lowercase letters don't change what word it is) and punctuation. Here is one form of the choose function:
def about(topic): """Return a select function that returns whether a paragraph contains one of the words in TOPIC.
>>> about_dogs = about(['dog', 'dogs', 'pup', 'puppy']) >>> choose(['Cute Dog!', 'That is a cat.', 'Nice pup!'], about_dogs, 0) 'Cute Dog!' >>> choose(['Cute Dog!', 'That is a cat.', 'Nice pup.'], about_dogs, 1) 'Nice pup.' """ assert all([lower(x) == x for x in topic]), 'topics should be lowercase.'
cats.py - C:\Users\G.D.TARUN\Desktop\cats.py (3.8.0) File Edit Format Run Options Window Help def choose (paragraphs, select, k): out = [] for i in paragraphs: if(select(i)): out.append(i) #appending if it returns true if (k
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
