1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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.