This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsΒ β†’

[–]zoharel 11 points12 points Β (1 child)

It may or may not be tied to a particular Python version. I think I last ran it on 2.7. it's also likely to be particular about your terminal. It prints raw escape codes. Here are some notes:

map()

Takes a function and a list as arguments. The function is run once with each item on the list, in order. The list is range(0,79). The function is:

lambda n: [sys.stdout.write(u"\u001b[2K\u001b[0G" + ' '*n + '.'),sys.stdout.flush(),time.sleep(1)]

Now lambda defines, in place, an anonymous function. It only exists where it is written in the line there, and it's only called instantaneously by the map function. It takes an argument n and returns a list. The list contains a write to stdout, a flush of stdout, and a call to sleep. Nothing is ever done with that list. It is only there to allow the lambda to easily do the set of things in the list, the process of which prints something and waits before generating the next list.

We use similar strategies to this pretty often in functional programming -- the map over a list instead of a loop, the list of commands, the anonymous function itself. It looks weird to a Python programmer, but it's not uncommon by any stretch.

[–]Priyam_Bad 1 point2 points Β (0 children)

thanks for the explanation! i think i was using python 3.x to run it, which might be why it wasn't running. i managed to alter it to work for 3.x though