1 回答

TA贡献1796条经验 获得超10个赞
你可以尝试这样的事情:
from datetime import datetime
listexample=[]
def examplefunc():
listexample.append(
{'example_record':len(listexample)+1,
'date':datetime.strptime(input('Date (yyyy/mm/dd): ' ), '%Y/%m/%d'),
})
#Define how many dates are you going to add
for i in range(int(input("How many dates are you going to add?\n:"))):
examplefunc()
def show_all_in_current_month(currentmonth): #receives the a month and filter the dicts that are in that month
print([dict for dict in listexample if dict['date'].month==currentmonth])
show_all_in_current_month(int(input("Which month do you want to filter the list with?\n:")))
添加回答
举报