Skip to main content
Data Science Wizardry Blog by Attila Vajda

Filter and taking breaks.

filter(w.startswith('P'), ['powerful', 'Python', 'is']) list(lambda: w)

Whenever I play, I gain insight. While mining the different elements of the puzzle, patterns of connections become apparent.

lambda: w
list()
filter()
['powerful', 'Python', 'is']
,
w.startswith('P')

w is the input of the lambda anonymous function.

filter(lambda w: w.startswith('P'))

If the word in the list starts with 'P', return the word.

>>> filter(lambda w: w.startswith('P'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: filter expected 2 arguments, got 1

filter() takes two arguments as input.

Filter the word from the list. Filter the element from the list, that satisfies condition. The condition is given by the function. I guess filter(function, list) is how filter works.

>>> filter(lambda w: w.startswith('P'), ['powerful', 'Python', 'is'])
<filter object at 0x10be93940>

Even though I don't see what the filter object is, filter() seems to work with a function and a list as inputs. Perhaps, list() transforms this filter object into something reasonable.

>>> list(filter(lambda w: w.startswith('P'), ['powerful', 'Python', 'is']))
['Python']

Taking breaks for elastic thinking and diffused mode seems to help finding solutions, because I found the solution to the last puzzle after returning from a break.[^1][^2]

While learning, micro-rest intervals can also be beneficial, [^3] but I struggle to establish the habit of always taking 10 sec rests every 2 minutes or so.

[1]: Oakley, B. (2014). Mind for Numbers. [2]: Mlodinow, L. (2018). Elastic. [3]: Huberman, A. (2021). Teach and Learn Better with a Neuroplasticity Super Protocol