python - while loop - IndexError: list index out of range -
python - while loop - IndexError: list index out of range -
maybe it's simple , didn't see mistake.
while list_a[y] in list_a != list_a[-1]: print(y);y=y+1 returns indexerror: list index out of range
list_a looks like:
['00001', '00001', '00002', '00009', '0000g', '0000k', '0000k', '0000u', '0000u', '00013', '0001b', '0001d', '0001d', '0001l', '0001l', '0001n', '0001q', '0001q', '0001r', '0001u'] and aim in end delete items list while iterating (that's why want utilize while loop instead of for y in range(len(list_a))).
think trying was:
while list_a[y] != list_a[-1]: ... i.e. "while we're looking @ item isn't equal lastly in list". however, there still issues; if items appear elsewhere in list equal lastly item?
the general way utilize list comprehension build new list appropriate items in old list:
list_b = [item item in list_a if some_test(item)] python python-2.7 while-loop
Comments
Post a Comment