3 ms·
This would also work: def make_window(min, max): min, max = sorted([min, max]) return lambda val: min <= val <= max
by iterati 12y ago
This would also work:
def make_window(min, max):
min, max = sorted([min, max])
return lambda val: min <= val <= max
- parennoob 12y agoSimple min and max on my computer reliably seems to take less time than the sorted solution, and also makes more sense to read. This is what I would intuitively expect anyway with the overhead of making the array. >>> timeit.timeit('x=4; y=3; x, y = sorted([x, y])') 0.49517297744750977 >>> timeit.timeit('x=4; y=3; x = min(x,y); y = max(x, y)') 0.2774021625518799