Generate a sequence of numbers in Python

user1460818 picture user1460818 · Jun 16, 2012 · Viewed 206.3k times · Source

How can I generate the sequence of numbers "1,2,5,6,9,10......" and so until 100 in Python? I even need the comma (',') included, but this is not the main problem.

The sequence: every number from 1..100, divisible by 4 with remainder 1 or 2.

Answer

Aleksei astynax Pirogov picture Aleksei astynax Pirogov · Jun 16, 2012

Every number from 1,2,5,6,9,10... is divisible by 4 with remainder 1 or 2.

>>> ','.join(str(i) for i in xrange(100) if i % 4 in (1,2))
'1,2,5,6,9,10,13,14,...'