简体   繁体   English

如何使用增量变化的辅助变量并行迭代两个列表?

[英]How to iterate through two lists in parallel using auxiliary variable with changing increments?

I have two lists in Python , like this:我在Python有两个列表,如下所示:

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.然后我想用辅助变量迭代,比如i ,因为当满足某些条件时(比如 EC 与 RG 不同),我希望这个迭代转到另一个元素,而不是下一个元素。 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 .我已经看到了zip 函数,但我没有找到如何使用它来做到这一点,因为这个function是一个iterable .

A for loop is not useful if you do not want to iterate a container while jumping indices.如果您不想在跳转索引时迭代容器,则 for 循环没有用。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM