Guest User

Untitled

a guest
Sep 4th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DAY_NAME_TO_ORDER = {
  2.     "monday": "first",
  3.     "tuesday": "second",
  4.     "wednesday": "third",
  5.     "thursday": "fourth",
  6.     "friday": "fifth",
  7.     "saturday": "sixth",
  8.     "sunday": "seventh"
  9. }
  10.  
  11. g = input("What day are you leaving on?? ")
  12.  
  13. matching_days = filter(lambda x: x in g.lower(), DAY_NAME_TO_ORDER.keys())
  14.  
  15. # You wouldn't usually do this but I worte this example in python 2
  16. # where filters return lists instead of iterators
  17. matching_days = list(matching_days)
  18.  
  19. if len(matching_days):
  20.     selected_day = matching_days[0]
  21.     print("That's a {0} day of the week".format(DAY_NAME_TO_ORDER[selected_day]))
  22. else:
  23.     print("I don't know what day that is!")
  24.  
  25.  
  26. input("PRESS ENTER TO CLOSE: ")
Advertisement
Add Comment
Please, Sign In to add comment