Skip to content

Instantly share code, notes, and snippets.

@llimllib
Created December 2, 2009 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llimllib/247442 to your computer and use it in GitHub Desktop.
Save llimllib/247442 to your computer and use it in GitHub Desktop.
#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