Skip to main content
Data Science Wizardry Blog by Attila Vajda

Comprehending list comprehensions while being bent by a massive object.

print([(x, y) for x in range(3) for y in range(3)])  
# [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]

[^3] I have an idea, this one liner could be a starting point to produce graphs.

[(0, 0), (0, 1), (0, 2), 
 (1, 0), (1, 1), (1, 2), 
 (2, 0), (2, 1), (2, 2)]
 
#or

***
***
***

I can ask the computer agent for five ways of making these representations with one liners.

I struggle with this visualisation.

>>> print(["*" for i in range(3)])
['*', '*', '*']

If I could make three lines, three rows in other words, then the rows could be joined.

Nice 😎:

>>> print([["*" for i in range(3)] for j in range(3)])
[['*', '*', '*'], ['*', '*', '*'], ['*', '*', '*']]

I am using the simple form of the problem.

Waking from my afternoon nap, lying in my bed, I focused on the sensations throughout my body, and I wondered what the real orientation of my body in space was. I felt the gravitation of the Earth, the bending of spacetime by this massive object. It didn't feel like I was being pulled downwards, it felt more as if my body was vertical and I was attached to this Earth from the side. Is spacetime bent spherically around the center of the Earth?

[^3] Mayer, C. (2020). Python One-Liners. No Starch Press.