
On Sun, Nov 28, 2021 at 10:52:03AM -0800, Christopher Barker wrote:
Back in the day Python had map, filter, and reduce.
And still does :-)
Then comprehensions were added, which are another way to express map and filter in one go.
I really like comprehensions.
But since then, there has been an informal movement, if you can call it that, back to map and filter.
I don't think there is a movement as such, I think that in the excitement of comprehensions, people rejected "confusing" functional idioms like map and filter and especially reduce (which got relegated from a builtin to a function in functools). But as comprehensions became commonplace and boring, and more people became aware of functional idioms from other languages, we've become more comfortable with them. Beside, map is often shorter: map(len, strings) (len(s) for s in strings) and people like shorter code.
Itertools is great, but it's not all that compatible with comprehensions :-(
That's an odd thing to say. itertools operates on pretty much any iterable, comprehensions are iterables. What do you think itertools is lacking when it comes to comprehensions?
I'm a bit confused as to why comprehensions seem to have become second-class citizens myself.
I don't think they are.
Granted, deeply nesting multiple comprehensions is pretty ugly, so a fluent interface to nesting transformations on iterables does have its appeal.
Indeed. -- Steve