Q:

Write a Python program to iterate over all pairs of consecutive items in a given list

0

Write a Python program to iterate over all pairs of consecutive items in a given list.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def pairwise(l1):
    temp = []
    for i in range(len(l1) - 1):
        current_element, next_element = l1[i], l1[i + 1]
        x = (current_element, next_element)
        temp.append(x)
    return temp
l1 = [1,1,2,3,3,4,4,5]
print("Original lists:")
print(l1)
print("\nIterate over all pairs of consecutive items of the said list:")
print(pairwise(l1))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now