Skip to content

Instantly share code, notes, and snippets.

@alexland
Last active August 29, 2015 13:57
Show Gist options
  • Save alexland/9520385 to your computer and use it in GitHub Desktop.
Save alexland/9520385 to your computer and use it in GitHub Desktop.
useful (but not common known) python idioms
# useful eg, for recursive functions such as merge sort or binary tree building/traversal in which sometimes the fn must return one of two portions of some container (a sequence, tree node, etc.)
def fnx(a):
if a % 2 == 0:
x = 45
y = None
else:
x = None
y = 3
return (x or y) + 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment