How to pass all items in list, through for loop. If iteration starts not from first element.
Lets jump to example right away:
We have list ['a','b','c','d'].
I want to go through all the items in this list using for loop. But if iteration starts not from first element, I want to came back oand start from first element.
Something like this:
lst = ['a','b','c','d']
start_index = 2
for loop_num in range(len(lst)):
item = lst[start_index+loop_num]
print item
It will print me:
>> c,d
Than rises IndexOutOfRange error
But I want result to be like this:
>> c, d, a, b
and if we change the start_index variable to 1 result suppose to be:
b, c, d, a
in case of start_index = 0
result: a, b, c, d
% – it is special operation. 3 % 5 = 3, 10 % 5 = 0,
read about it Remainder and Python Doc