Remove all elements of a set that contain a specific char

Viewed 594

I have a set of a few thousand primes generated from a generator:

primes = set(primegen()) = set([..., 89, 97, 101, 103, ...])

Some of those primes have a zero in them. I would like to get rid of them. Is there a way to do this all at once?

Currently I am removing elements as I loop through primes, with a regex match:

import re
zero = re.compile('.+0.+') 

while primes:
    p = str(primes.pop())
    if zero.match(p):
        continue
    # do other stuff

I think this is the best way, but am curious if I'm wrong.

5 Answers
Related