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

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -