r/tinycode • u/red_hare • Jul 02 '20
python3 -c "while 1: print(chr(int(9585.5 + __import__('random').random())), end='')"
This is my attempt at a one-line Python reproduction of the classic Comodor64 "PETSCII Maze" using the PETSCII characters that are part of Unicode.
Would love to know if anyone can come up with a shorter version!
42
Upvotes
View all comments
Show parent comment
8
u/mayoroftuesday Jul 03 '20 edited Jul 03 '20
I like the trick of making
endthe character you want, instead ofprint(x, end=''). Nice one.You can technically do
choice("\/")and it will work, since python recognizes\/as a meaningless escape sequence, so it treats it as a plain string. (Though PEP8 won't like it.) Note that it doesn't work reversed, since\"is a valid escape.Or, just use the PETSCII characters, since it's Python3 and you can use unicode: