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

jquery - How do you format the date used in the popover widget title of FullCalendar? -

Bubble Sort Manually a Linked List in Java -

asp.net mvc - SSO between MVCForum and Umbraco7 -