Regular Expression for Prime Numbers (or How I came to fail at them, and love the bomb)

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Feb 14 06:26:24 EST 2008


cokofree:
> Sadly that is pretty slow though...

It's quadratic, and it's not even short, you can do (quadratic still):

print [x for x in range(2, 100) if all(x%i for i in range(2, x))]

In D you can write similar code.
Bye,
bearophile



More information about the Python-list mailing list