python two or three continuous items in list

Python list 中连续2-3个对象

1.前后连续两天

1
2
for date in [eval_obj.date_range[i:i+2] for i in range(len(eval_obj.date_range) - 1)]:
print date[0], date[1]

2.时间间隔1-3天

1
2
3
for t in [time_list[i:i + 3] for i in range(len(time_list) - 1)]:
if len(t) == 3:
print(t[0], t[2])