2 ms·
def f(x): return not x or x == [x[0]] * len(x)
by makecheck 17y ago
def f(x):
return not x or x == [x[0]] * len(x)
- RiderOfGiraffes 17y agoSmall, 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])