python - More pythonic alternative for getting a value in range not using min and max -
i have this:
a = min(max(x, 1), 100)
is there more pythonic?
what about:
a = 1 if x < 1 else 10 if x > 10 else x
it gives readability wanted without redundancy of version in comment. verbose because defines centre case first , has distinguish between 2 ends. way of doing cuts ends of first , left in range.
Comments
Post a Comment