3 ms·
Here's how it would look in python: from functools import reduce def min2(a, b): if a < b: return a return b def min(list):
by rovolo 7y ago
Here's how it would look in python:
from functools import reduce
def min2(a, b):
if a < b:
return a
return b
def min(list):
return reduce(min2, list, None)
- saagarjha 7y ago> from functools import reduce Oh, Python…
- scrollaway 7y agoreduce() used to be in the builtins in python 2.x. It was removed due to low usage. Keeping the builtins list tiny is a core principle of the language.
- threatofrain 7y agoGuido van Rossum on reduce: > So now reduce(). This is actually the one I've always hated most, because, apart from a few examples involving + or *, almost every time I see a reduce() call with a non-trivial function argument, I need to grab pen and paper to diagram what's actually being fed into that function before I understand what the reduce() is supposed to do. So in my mind, the applicability of reduce() is pretty much limited to associative operators, and in all other cases it's better to write out the accumulation loop explicitly. https://www.artima.com/weblogs/viewpost.jsp?thread=98196 https://www.artima.com/weblogs/viewpost.jsp?thread=98196
- saagarjha 7y agoLow usage because Python makes it annoying to use…
- bobbylarrybobby 7y agoProbably low usage because it sort of relies on lambdas (not exactly, you can define one-off functions, but most people don’t like to) and python lambdas are terrible.
- kazinator 7y agoYou mean, breaking users is the principle of the language.
- scrollaway 7y agoYour post doesn't mean anything; but even the most charitable meaning I can assign to it is pretty bad. Stuff like this is no better than "php bad!!1".