Skip to main content
Data Science Wizardry Blog by Attila Vajda

Tuple comprehension at the end of time.

tuple(x % 2 != 0) for x**3 in range(1, 6) if

The idea is to craft one-liners similar to validating time in a cognitive clock exercise. Let there be awesome connectivity in the brain! 😌 [^1]

tuple()
for
x**3
x % 2 != 0
in range(1, 6)
if

[x**3 for x in range(1, 6) if x % 2 != 0]

If x is odd, add the cube of x to the list. I don't know what tuple() is for. What are tuples for?

Since there are no [] in the puzzle, the solution might be a tuple() comprehension. Do tuple comprehensions exist?

In fact, they do:

>>> tuple(x**3 for x in range(1, 6) if x % 2 != 0)
(1, 27, 125)

[^1]: Arrowsmith-Young, Barbara. (2012). The Woman Who Changed Her Brain.