How to check if date is in a list of date strings?
date, list, python
Solution
You are comparing strings with python `datetime.date` objects; you need to convert the date object to a string for the comparison, using the `.strftime()` method:
today = date.today().strftime('%Y-%m-%d')
print today in dates # Will print "True" or "False"
To illustrate this further:
>>> from datetime import date
>>> date.today()
datetime.date(2012, 8, 28)
>>> date.today() == '2012-08-28'
False
>>> date.today().strftime('%Y-%m-%d') == '2012-08-28'
True
Alternatively, you can use the `.isoformat()` method, which uses the exact same output format:
>>> date.today().isoformat()
'2012-08-28'
Problem
This will always print false. How can I check if the date is in the array and print the proper thing? ``` dates = [ "2012-09-03", "2012-10-08", "2012-10-09", "2012-11-12", # .. more values snipped for brevity "2013-04-19", "2013-05-27", ] if date.today() in dates: print "true" elif date.today() not in dates: print "false" ```