How can I find whether each value in a list fits the criteria or not?

Viewed 32

So I created a code to find prime numbers, and my is_prime(k): function works, however when I'm trying to find all the prime numbers in a given list as indicated in prime(number): it doesnt work. Can someone give me examples to draw from?

1 Answers

Use your is_prime function:

def sans_primes(numbers):
    return [n for n in numbers if is_prime(n)]

Or to only get the unique values:

def sans_primes(numbers):
    return set(n for n in set(numbers) if is_prime(n))
Related