Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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
Add Comment
Please, Sign In to add comment