Converting a for loop to a while loop

前端 未结 5 1022
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 03:19

I am new to Python and I need to convert a for loop to a while loop and I am not sure how to do it. This is what I am working with:



        
5条回答
  •  感情败类
    2020-12-12 04:14

    The first answer is the straightforward way, there is another way, if you're allergic to incrementing your index variables:

    def scrollList(myList):
      negativeIndices = []
      indices = range(0,len(myList)):
      while indices:
            i = indices.pop();
            if myList[i] < 0:
                 negativeIndices.append(i)
      return negativeIndices
    

提交回复
热议问题