Actually that example is not even valid Python code, you'll get an 'n not defined'. Furthermore you need to indent it properly. You probably want something like this:
def primes_upto(limit):
is_prime = [False] * 2 + [True] * (limit - 1)
for n in range(int(limit**0.5 + 1.5)):
if is_prime[n]:
for i in range(n*n, limit+1, n):
is_prime[i] = False
return [i for i, prime in enumerate(is_prime) if prime]
And VB6 you can actually do this on one line :)
Sub Eratost() : Dim sieve() As Boolean : Dim n As Integer, i As Integer, j As Integer: n = InputBox("limit:", n) : ReDim sieve(n) : For i = 1 To n : sieve(i) = True : Next i : For i = 2 To n : If sieve(i) Then : For j = i * 2 To n Step i : sieve(j) = False : Next j : End If : Next i : For i = 2 To n : If sieve(i) Then Debug.Print i : Next i : End Sub 'Eratost
If you want one-liner programs, we should really force people to use perl which is famous for that. Python is not friendly to 'one-liner' types of programs because it forces indentation.
But really, the parser is supposed to work with you, not against you, so why not write it on several lines to help readability? I fail to see how writing code on one line really proves its power.
For bragging rights, you could go full-genius mode [instead of full-retard] with APL (change 100 to whatever you want the vector of primes to be) :
(~vv.×v)/v1100
EDIT: Damn it, you can't even put APL code in Slashdot. Here is a link to explain the code