Skip to content

Instantly share code, notes, and snippets.

@categulario
Created May 23, 2012 00:04
Show Gist options
  • Save categulario/2772442 to your computer and use it in GitHub Desktop.
Save categulario/2772442 to your computer and use it in GitHub Desktop.
Lista de números primos del 1 al 100 en python (una sola línea)
#Lista de numeros primos entre 1 y 100 en una sola linea
c = [i for i in xrange(2,101) if (i%2!=0 or i==2) and (i%3!=0 or i==3) and (i%5!=0 or i==5) and (i%7!=0 or i==7)]
print c
@ignaciovillela
Copy link

ignaciovillela commented Jun 7, 2016

Hice un código en una linea que genera los números primos de 1 a n
Complete code here. (Código completo aquí)

n = 100
p = [2] + [x for x in range(3, n+1, 2) if not [y for y in range(3, int(x**0.5)+1, 2) if (float(x) / y).is_integer()]]
print(p)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment