Roughly speaking I am looking for a more elegant alternative for this snippet:
# my_list = range(6) # example list
my_list = ["this", "is", "an", "example", "list"]
max = len(my_list)
for i, elem in enumerate(my_list, start=1):
if i < max:
print elem, my_list[i]
which produces:
this is
is an
an example
example list
Is there some builtin for that?
Edit: I should have said, that I took range(6) as a representant for any iterable to avoid confusion. The goal was to iterate over an iterable pairwise pictured by the result above.
I usually do this: