Question: Write the choose function, which selects which paragraph the user will type. It takes a list of paragraphs (strings), a select function that returns True

Write the choose function, which selects which paragraph the user will type. It takes a list of paragraphs (strings), a select function that returns True for paragraphs that can be selected, and a non-negative index k. The choose function return's the kth paragraph for which select returns True. If no such paragraph exists (because k is too large), then choose returns the empty string. def choose(paragraphs, select, k): """Return the Kth paragraph from PARAGRAPHS for which SELECT called on the paragraph returns true. If there are fewer than K such paragraphs, return the empty string. """ For an example of it working: >>> from cats import choose >>> ps = ['short', 'really long', 'tiny'] >>> s = lambda p: len(p) <= 5 >>> choose(ps, s, 0) 'short' >>> choose(ps, s, 1) 'tiny'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!