1 回答

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超10個(gè)贊
你可以嘗試這樣的事情:
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:")))
添加回答
舉報(bào)