Last active
August 29, 2015 13:57
-
-
Save alexland/9520385 to your computer and use it in GitHub Desktop.
useful (but not common known) python idioms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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