def ListCreate(*args):
items = none
for i in range(len(args)-1,-1,-1):
items = join(args[i], items)
return items
a = ListCreate(1,2,3,4,5,6)
b = ListCreate(20150602, 20150603, 20150604, 20150605, 20150606, 20150607)
python中的列表是有序的,所以我希望列表a中的element 0
与列表b中的element 0
相对应。
即。
(1,20150602)(2,20150603)(3,20150604)
#etc
现在,我想创建一个搜索循环,询问if a(n)==a(n+1) and b(n+1) - b(n) <= 3
...打印条件保持为真的所有元素。
答案 0 :(得分:0)
很难理解你想要的输出,但这是我最好的猜测:
In [39]:
a = [1,1,3,4,4,6]
b = [20150602, 20150603, 20150604, 20150605, 20150606, 20150607]
c = zip(a, b)
print c
for i in range(0, len(c)-1):
if c[i][0] == c[i+1][0] and c[i+1][1] - c[i][1] <= 3:
print c[i]
[(1, 20150602), (1, 20150603), (3, 20150604), (4, 20150605), (4, 20150606), (6, 20150607)]
(1, 20150602)
(4, 20150605)