SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. months = ['January',
  2.       'February',
  3.       'March',
  4.       'April',
  5.       'May',
  6.       'June',
  7.       'July',
  8.       'August',
  9.       'September',
  10.       'October',
  11.       'November',
  12.       'December']
  13.  
  14.   def valid_month(month):
  15.      for x in months:
  16.          if x==month.capitalize() :
  17.              print x
  18.    
  19. valid_month("january")  
  20.   valid_month("January")
  21.   valid_month("foo")
  22.   valid_month("")
  23.   valid_month("jaNuary")
  24.    
  25. def valid_month(month):
  26.     for x in months:
  27.         if x[1:] == month[1:] and x[0].capitalize() == month[0].capitalize():
  28.             print x
  29.    
  30. In [4]: "January"=="janUAry".capitalize()
  31. Out[4]: True
  32.    
  33. def valid_month(month):
  34.      if month and month[0].capitalize()+month[1:] in months:
  35.          print(month)
  36.      else:
  37.          print(month,"is not found")
  38.    
  39. >>> valid_month("january")
  40. january
  41. >>> valid_month("January")
  42. January
  43. >>> valid_month("foo")
  44. foo is not found
  45. >>> valid_month("")
  46.  is not found
  47. >>> valid_month("jaNuary")
  48. jaNuary is not found
  49.    
  50. any(t.isupper() for t in month[1:])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top