I have the following function:
function(['28-02-2016','31-02-2016'])
['february', '*']
EDIT (full function)
import calendar
def function(monthList):
months = {"01": "january", "02":"february", "03":"march", "04":"april", "05":"may", "06":"june", "07":"july", "08":"august", "09":"september", "10":"october", "11":"november", "12":"december"}
returnList = []
for monthStr in monthList:
month = str(monthStr)[3:5]
if month in months.keys():
if int(monthStr[:2]) <= calendar.monthrange(int(monthStr[-4:]), int(monthStr[3:5]))[1]:
returnList.append(months[month])
else:
returnList.append("*")
else:
returnList.append("*")
return returnList
If the date is right, the function creates a list where the month is put, otherwise a '*'
is put. But if I write:
function([02-02-20a1]:
I get this error:
6 month = str(monthStr)[3:5]
7 if month in months.keys():
---> 8 if int(monthStr[:2]) <= calendar.monthrange(int(monthStr[-4:]), int(monthStr[3:5]))[1]:
9 returnList.append(months[month])
10 else:
ValueError: invalid literal for int() with base 10: '20a1'
So Python is telling me I have to put a control in the list number 8. How do I manage to tell the function to act like this?
function(['02-02-19a1'])
[*]