如何解决此嵌套for循环问题 [英] How do I solve this nested for loop problem
本文介绍了如何解决此嵌套for循环问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好。
i想要使用相同的i和j索引,例如,
next_azimuth(list4 [0],list2 [0]),
next_azimuth(list4 [1],list2 [1])
not next_azimuth(list4 [1],list2 [3] ),所以请帮助我
Hello everyone
i want to use same i and j indexes for instance,
next_azimuth(list4[0],list2[0]),
next_azimuth(list4[1],list2[1])
not next_azimuth(list4[1],list2[3]) ,so please help me
for i in range(len(list4)):
for j in range(len(list2)):
if i != j :
continue
az = float(next_azimuth(list4[i], list2[j]))
list4.append(az)
我尝试了什么:
i尝试if语句但不工作
What I have tried:
i tried if statement but not working
推荐答案
我不知道嵌套循环的原因,但您可以尝试:
I don't know the reason of nested loops, but you can try:
for i in range(len(list4)):
for j in range(len(list2)):
if i == j :
az = float(next_azimuth(list4[i], list2[j]))
list4.append(az)
假设list4总是比list2长或者长度相同,那么:
Assuming that list4 will always be longer than, or the same length as, list2 then:
for i in range(len(list4)):
if i < len(list2):
az = float(next_azimuth(list4[i], list2[i]))
list4.append(az)
如果list2较长,则将
和 if
语句分别更改为list2和list4。
if list2 is longer, then change the for
and if
statements to list2 and list4 respectively.
这篇关于如何解决此嵌套for循环问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文