Hacker News new | ask | show | jobs
by teddyh 14 days ago
Note that only Python standard modules are imported, no third-party libraries.

The “random” module is needed, because Python does not have a built-in replacement for BASIC’s RND(). The “time” module is merely to add delays, to emulate the style of normal BASIC interpreters on old – i.e. very slow – computers. You could remove it without any change in output. And lastly, the “itertools” module is used to get an infinite loop on a Python one-liner; Python, with its whitespace-based block structure, has a hard time doing anything significant in a single line otherwise.

1 comments

You could use `iter(lambda:1,0)` to get an infinite iterator, then itertools can be dropped.
Nice!

  python3 -c 'import random, time; any(time.sleep(0.01) or print(random.choice("\u2571\u2572"), end="", flush=True) for x in iter(lambda: 0, 1))'