Skip to content

Instantly share code, notes, and snippets.

@davidnuon
Created July 3, 2012 01:11
Show Gist options
  • Save davidnuon/3036809 to your computer and use it in GitHub Desktop.
Save davidnuon/3036809 to your computer and use it in GitHub Desktop.
One-liner in python to list all prime numbers from 2 to n
primelist = lambda n : [x for x in xrange(2, n) if not 0 in map(lambda z : x % z, xrange(2,x))]
print ", ".join(map(str, primelist(100)))
@SATYADAHAL
Copy link

print(list(set([0 if([1 if(x%j==0) else 0 for j in range(2,x)].count(1)) else x for x in range(int(input("Enter the nth term: ")) +1 )]))[2:])
Hope this one helps

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