Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a test case that fails when run on a buggy contains_non_satisfier. def contains_non_satisfier(obj: Union[int, list], predicate: Callable[[int], bool]) -> bool: Return whether obj contains

Write a test case that fails when run on a buggy contains_non_satisfier.

def contains_non_satisfier(obj: Union[int, list], predicate: Callable[[int], bool]) -> bool: """Return whether obj contains at least one element that does *not* satisfy predicate.

If obj is an int, returns True if obj does *not* satisfy predicate (i.e. predicate(obj) is False)

>>> def p(n: int) -> bool: ... return n < 10 >>> contains_non_satisfier(5, p) False >>> contains_non_satisfier(15, p) True >>> contains_non_satisfier([5, 2, [15, 7], 9], p) True """ if isinstance(obj, int): if not predicate(obj): return True else: return False list_of_ints = [x for x in obj if isinstance(x, int)] list_of_lists = [y for x in obj if isinstance(x, list) for y in x] obj = list_of_lists + list_of_ints if len([x for x in obj if predicate(x)]) != 0: return True return False

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

What factors or events contribute to variances?

Answered: 1 week ago

Question

What are the consolidated financial statements?

Answered: 1 week ago