Skip to content

Instantly share code, notes, and snippets.

@built
Created June 6, 2009 21:30
Show Gist options
  • Save built/125008 to your computer and use it in GitHub Desktop.
Save built/125008 to your computer and use it in GitHub Desktop.
# One of several ways to do a ternary operation in Python
# For more discussion, see: http://drj11.wordpress.com/2007/05/25/iversons-convention-or-what-is-the-value-of-x-y/
# "AB"[True] => A, likewise "AB"[False] => B
# In this way you can index any two item list with a test:
card_type = ["Low", "High"]][card_value < 10]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment