from itertools import imap, count, takewhile for i in takewhile(lambda x: x<20, imap(lambda x: x*2, count())): print i,