3 ms·
Would the Python3 version be: map(merge_func, zip(X,Y))?
by cma 6y ago
Would the Python3 version be:
map(merge_func, zip(X,Y))?
- lovasoa 6y agoNo. In idiomatic python, you would not use a functional approach for something like this, but if you really wanted to, you could do: def teeing(reducer1, reducer2): return lambda acc,elem: ( reducer1(acc[0],elem), reducer2(acc[1],elem) ) functools.reduce( teeing( (lambda l,elem: [elem] + l), (lambda l,elem: elem.price + l) ), cart.getProducts(), ([], 0) )
- mjburgess 6y agoIt is quaint how there is supposed to be an "idiomatic python" just as mypy, "pattern statements", walrus operators, etc. are being added. "Idomatic python" is dead, and lives now only as a pretty dumb ideology which states: everything must be phrased as a naively-typed naively-imperative program. Python is being made, retroactively, a bad imperative programming language: largely because its creator always thought that's what he'd made (he is wrong). It's a great tragedy "pythonic" has become this: a back-reaction against the times (of increasing adoption of functional programming driven by increasing data-transformation needs).
- eskaytwo 6y agoThat seems a very broad statement. Are there any such articles on this topic? I don’t see how Pythonic as a concept has to be mutually exclusive with new language features. To me, the features you cite seem to fit the Pythonic approach intuitively.
- cma 6y agoAh I didn't read their description well and didn't realize it was doing reductions.
- Doxin 6y agoIt looks to be the inverse of that. i.e. split a single stream of stuff so two different things can consume it. In python you'd do something like that using itertools.tee, though I think the java API goes about it quite differently. https://docs.python.org/3/library/itertools.html#itertools.tee https://docs.python.org/3/library/itertools.html#itertools.t...
- deleted 6y ago[deleted]