When using zip do you need to use enumerate and convert the zip tuples to a list to access the previous index (i.e. index -1)
e.g.
list1 = [1, 3, 4, 8, 10]
list2 = [1, 3, 6, 7, 9]
combined_list = list(zip(list1, list2))
for i, v in enumerate(combined_list):
if i > 0:
print(combined_list[i-1])
Put simply, is that the most pythonic way?
list slice, or enumerate's second parameter, as pointed out before.
for i, v in enumerate( combined_list[1:] ):
print( i, v, i-1, combined_list[i] )
for i, v in enumerate( combined_list, 1 ):
print( i, v, i-1, combined_list[i] )
0 (3, 3) -1 (1, 1)
1 (4, 6) 0 (3, 3)
2 (8, 7) 1 (4, 6)
3 (10, 9) 2 (8, 7)