A Program that prints the numbers from 1 to 100

Jussi Piitulainen harvesting at is.invalid
Mon Nov 16 08:39:50 EST 2015


Chris Angelico writes:
>
> Here's another version, but with a deliberate bug in it. [- -]

This one recycles fish in a way that looks a bit worrying but it seems
to work. If there's a bug, it's not deliberate. Except stopping at 15 is
deliberate.

from contextlib import contextmanager as fish
from collections import defaultdict as fowl
@fish
def fish(fish):
    chip = fowl(str)
    chip.update(((fowl(int)[fish],fish),))
    yield chip
with fish("Fish") as f, fish("Bush") as b:
    print(*("{}{}".format(f[k%3],b[k%5]) or k for k in range(1,16)))

# prints:
1 2 Fish 4 Bush Fish 7 8 Fish Bush 11 Fish 13 14 FishBush



More information about the Python-list mailing list