3 ms·
Small, clean, clear. Fails for tuples. One could use: def f(x): return not x or list(x) == [x[0]] * len(x) Does have the downside that it constructs a l
by RiderOfGiraffes 17y ago
Small, clean, clear. Fails for tuples. One could use:
def f(x): return not x or list(x) == [x[0]] * len(x)
Does have the downside that it constructs a list, which the min==max solution doesn't.
I wonder if there is a single "ideal" solution ...
- makecheck 17y agoThis works for a list of numbers (array or tuple), as long as numbers aren't negative: def f(x): 0 == sum([y - x[0] for y in x])