#!/usr/bin/env python
# Notice: Generator expressions have the same syntax as list comprehensions.
# They are only enclosed by parantheses.
schaltjahre = (x for x in range(1870,2130) if ((not x%4) and (x%100)) or (not x%400))
print 'Die folgenden Jahre sind Schaltjahre'
# Generator expressions are a bit more complicated than list comprehensions.
# Therefore we have to query one element in a time using next().
while True:
try:
schaltjahr = schaltjahre.next()
except:
break
else:
print schaltjahr
# If we wanted to cycle through the generator expression once more,
# we have to reset its internal pointer. See documentation for more
# information.