Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
You can’t perform that action at this time.