Created
December 2, 2009 18:57
-
-
Save llimllib/247442 to your computer and use it in GitHub Desktop.
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
#demonstrate nested list comprehensions as cartesian set | |
deck_of_cards = [(suit, rank) for suit in ("hearts", "diamonds", "spades", "clubs") | |
for rank in range(13)] | |
####################################### | |
#demonstrate functions as first-class values | |
def double_str(x): | |
return str(x) + str(x) | |
def triple_str(x): | |
return str(x) + str(x) + str(x) | |
adictionary = {"something": double_str, | |
"or_other": triple_str} | |
for key, func in adictionary.iteritems(): | |
print func(key) | |
# somethingsomething | |
# or_otheror_otheror_other | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment