I'm truly baffled by how insane the `map/reduce/filter` iterator API for #Python is. Most languages, even JavaScript, have some sort of "other_list = the_list.map().filter()" API. Except Python (and PHP?).

Now, I can imagine that a language that primarily deals with string manipulation or DOM management or so, to have a crappy API for handling large lists of data. But python's entire success comes from "handleing large lists of data", yet the tools to do so are infuriating.

@berkes I'm fairly certain Python has this, but before i go figure out the exact syntax I want to understand your ask a bit better. Are you saying the functionality doesnt exist at all, or simply that you cant chain them together and they need to be on seperate lines, or something else I'm missing?

@berkes

Python does have the functions though:

filter(other_func, map(the_func, the_list))

That should be roughly the same as what you asked for... Are you just complaining about the syntax, seems functionally pretty interchangable.

@freemo I was referring to that. The insanity being that they are global functions and not something you call on a iterator like every other language has.

@berkes @freemo In Python they are functions, not methods, because they work with any iterable (strings, lists, tuples, bytes, literraly any containers, even the ones you create). It's easier than having to implement a map and a reduce function on every container.

But in Python we don't even use map and filter, comprehensions are (very often) more readable:

>>> sum(map(abs, filter(lambda x: x > 10, the_iterable)))

vs

>>> sum(abs(x) for x in the_iterable if x > 10)

@mdk @freemo Python could have the Ruby way where iterators are modules (shared behavior) that's mixed in. Or java, where it's an interface. Or the rust way where .iter() turns anything that wants to, into an actual Iterator.

If the reasons are 'technical limitations' it only strengthens my point that Python is doing a poor job here.

Follow

@berkes

They could have done it sure. I dont think anyone is denying the style you suggest isnt doable.

@mdk

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.