当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Is there any difference betwwen these two forms of for-loop?

问题描述:

This question already has an answer here:

  • 'Return' keyword returns only one element from a loop?

    3 answers

网友答案:

The first solution basically says "return all (left, right) pairs that match the following criteria"

The second solution says "search for a pair, that matches the following criteria. As soon as one is found, return it". Therefore only one is returned. I haven't tested this, but I it should be the first one encountered, not the last one.

To fix it: instead of returning a pair which is found in the second solution, add it to an array of solutions, and return that array after the for loop.

分享给朋友:
您可能感兴趣的文章:
随机阅读: