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

Popular posts from this blog

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -