@asmeurer@willmcgugan Exactly. Just the simple case of `x in "abc"`.
You get x= a, b, c, ab, bc, abc...
But `x in {"a", "b", "c"}` is more explicit. And that is better than implicit.
@mathsppblog Yes, but readability counts.
(also, maybe pass the bounds)
((also, you made me question my math 😅 I had to triple check your version))
def clamp(value, low, high):
if value < low:
return low
if value > high:
return high
return value
@mathsppblog Looking at the repo I have a small tip.
Insert your multiline sample input as:
inp = """\
...some...
...random...
...data...
"""
That way you start on a nicely indented first line and every line ends with the new line separator.
@mathsppblog Another dangerous pitfall is this:
assert (
'foo' == 'bar',
"This will never fail."
)
Multiline asserts.
Thankfully, newer Python versions warn you about this.
@mathsppblog@willmcgugan And, as a fellow lecturer.. many times were my students baffled by the fact that print always returns None.
I've seen:
def foo(x):
return print(x)