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:
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