我有一个日期时间对象列表,并希望找到在特定时间范围内的对象:
import datetime
dates = [ datetime.datetime(2007, 1, 2, 0, 1),
datetime.datetime(2007, 1, 3, 0, 2),
datetime.datetime(2007, 1, 4, 0, 3),
datetime.datetime(2007, 1, 5, 0, 4),
datetime.datetime(2007, 1, 6, 0, 5),
datetime.datetime(2007, 1, 7, 0, 6) ]
#in reality this is a list of over 25000 dates
mask = (dates>datetime.datetime(2007,1,3)) & \
(dates<datetime.datetime(2007,1,6))
但是,这会导致以下错误:“TypeError: can't compare datetime.datetime to list”
如何修复我的代码?