Top-rated recipes tagged "ternary"http://code.activestate.com/recipes/tags/ternary/top/2012-06-06T12:00:52-07:00ActiveState Code RecipesRange comparison (Python)
2012-06-06T12:00:52-07:00Charlie Clarkhttp://code.activestate.com/recipes/users/4171013/http://code.activestate.com/recipes/578158-range-comparison/
<p style="color: grey">
Python
recipe 578158
by <a href="/recipes/users/4171013/">Charlie Clark</a>
(<a href="/recipes/tags/case/">case</a>, <a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/switch/">switch</a>, <a href="/recipes/tags/ternary/">ternary</a>).
</p>
<p>Although Python now has something similar to ternary operator with the result if ... else other result construction and this allows chaining (adding additional conditions on the if side, this soon becomes unreadable. A common use case is to filter values by ranges so I wrote the following when porting some code from PHP once I found I no longer understand the logic for a simple three-way filter.</p>