Ygor Serpa
1 min readMay 25, 2022

--

This reminds me a lot of C# LINQ (using the extension methods syntax, not the SQL-like one). I can definitively see an use for that, however, I guess it is more a matter of audience. As a data scientist, most of the time I would write queries such as yours I would do it in Pandas or right from SQL, which have somewhat similar APIs/tools.

Just as a minor note, you can also comprehend sets and generators in Python.

{a for a in array} # comprehends a set

(a for a in array) # just creates a generator for the sequence

As for "Python users favor comprehensions over map and filter", I agree with you that the syntax is just way cleaner using comprehensions. Plus, there is no need to create that many lambdas. Finally, you can do both map and filter at once using comprehensions, which is a far more compact. For instance:

[a ** 2 for a in range(1, 100) if a % 2 == 0] # gets the squares of all even numbers from 0 to 100

--

--

Ygor Serpa
Ygor Serpa

Written by Ygor Serpa

Former game developer turned data scientist after falling in love with AI and all its branches.

No responses yet