如果这是你想要的,一个稍微容易理解的解决方案,没有依赖性。
a = '01/08/2017'
b = '28/08/2017'
c = ['01/08/2017', '20/08/2017', '21/08/2017', '22/08/2017', '23/08/2017', '24/08/2017', '25/08/2020', '26/08/2020', '27/08/2020', '28/08/2020']
a = a.split("/") #break requirements into components
b = b.split("/")
answerList = [] # form the final list structure
for i in range(0, len(c)): #iterate through all of c
cHolder = c[i].split("/") #break c into components
componentValidator = 0 # simple all-or-nothing counter
for j in range(3): # go through every component
if (int(a[j]) <= int(cHolder[j]) <= int(b[j])): # check ranges
componentValidator = componentValidator + 1 # for each component
if componentValidator == 3: # if all correct
answerList.append(c[i]) # add to final answers
print(answerList) # print final answers
输出:
['01/08/2017', '20/08/2017', '21/08/2017', '22/08/2017', '23/08/2017', '24/08/2017']