reg: playing with the list

Laurent Claessens moky.math at gmail.com
Fri Jun 24 10:29:42 EDT 2011


> You might try  writing the boolean function is_prime(n) for almost any n.
>
> There was a recent discussion on this topic.

Since the guy is "new in programming", I complete the answer, just in 
case. Using the function is_prime(n),

FIRST POSSIBILITY :

new_list=[]
for n in old_list:
    if is_prime(n):
       new_list.append(n)

SECOND POSSIBILITY :

new_list=[ n for n in old_list if is_prime(n) ]



There is a primiality test in Sage which is basically a module over 
python (www.sagemath.org).

Have a good WE
Laurent



More information about the Python-list mailing list