'How to iterate over items in a list using previous item [duplicate]

list = [1, 2, 3, 4, 5] How can I iterate over each item using the previous item? The previous item for the first element would just be 0. For example, something like this:

print(list[1] + 0)
print(lst[2] + list[1])
print(lst[3] + list[2])

I know you can do this with sum(), but I need to specifically iterate like this because the actual code is much more complicated than that.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source