Guest User

Untitled

a guest
Apr 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #demonstrate nested list comprehensions as cartesian set
  2.  
  3. deck_of_cards = [(suit, rank) for suit in ("hearts", "diamonds", "spades", "clubs")
  4. for rank in range(13)]
  5.  
  6. #######################################
  7. #demonstrate functions as first-class values
  8.  
  9. def double_str(x):
  10. return str(x) + str(x)
  11.  
  12. def triple_str(x):
  13. return str(x) + str(x) + str(x)
  14.  
  15. adictionary = {"something": double_str,
  16. "or_other": triple_str}
  17.  
  18. for key, func in adictionary.iteritems():
  19. print func(key)
  20. # somethingsomething
  21. # or_otheror_otheror_other
Add Comment
Please, Sign In to add comment