0

I have two lists in Python, like this:

RG = [30, 30, 30, 50, 50, 50, 70, 70, 80, 80, 80]
EC = [2, 2, 2, 25, 25, 25, 30, 30, 10, 10, 10]

and I want to iterate over then with an auxiliar variable, like i, because when some condition is met (like EC is different of RG), I want that this iteration go to another element that it's not the next one. Like:

for i in ?:
    // code
    if EC != RG:
        i = i + 5;
    // code

I already saw zip function, but I didn't found how to do this using it, because this function is an iterable.

7
  • for i in range(zip(RG, EC)): if EC[i] != RG[i]: i=i+5; # code Commented Aug 12, 2019 at 13:59
  • @BlueRineS i got TypeError: 'zip' object cannot be interpreted as an integer Commented Aug 12, 2019 at 14:06
  • should be len(zip... my bad Commented Aug 12, 2019 at 14:08
  • @BlueRineS now I got TypeError: object of type 'zip' has no len() Commented Aug 12, 2019 at 14:10
  • aah, my bad. then do len(list(zip... Commented Aug 12, 2019 at 14:11

1 Answer 1

2

A for loop is not useful if you do not want to iterate a container while jumping indices. In this case a while would be more conducive to your task:

i = 0
while i < len(RG):
    # code
    if EC[i] != RG[i]:
        i += 5;
    else: i += 1
    # code
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.