1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

#sieve of euler s=[] t=[] for i in xrange(30): s.append(i+2) s.pop() print s j=0 i=s[j] while i*i < 30: for k in s: l=k*i if l in s: t.append(l) for h in t: if h in s: s.remove(h) j=j+1 i=s[j] print s

1 2

[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30] [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]