Python how to convert this for loop into a while loop
Posted
by
user1690198
on Stack Overflow
See other posts from Stack Overflow
or by user1690198
Published on 2012-09-26T22:37:49Z
Indexed on
2012/10/01
3:38 UTC
Read the original article
Hit count: 117
python
I have this for a for loop which I made I was wondering how I would write so it would work with a while loop.
def scrollList(myList):
negativeIndices=[]
for i in range(0,len(myList)):
if myList[i]<0:
negativeIndices.append(i)
return negativeIndices
So far I have this
def scrollList2(myList):
negativeIndices=[]
i= 0
length= len(myList)
while i != length:
if myList[i]<0:
negativeIndices.append(i)
i=i+1
return negativeIndices
© Stack Overflow or respective owner