0

I am retrieving a list of numbers (scores) as well as a separate list of corresponding games.

Some of the scores are -1 in the scores list.

These -1 scores need to be deleted and I need to delete the corresponding game element.

I have tried the following:

for i, score in enumerate(scores):
    if score<0:
        del scores[i]
        del games[i]        

However everytime I run the above.. it I always still have one game and score (in scores list) which has a score of -1.

There is always one left, all others get deleted and I've tried for different scores and games lists.

Any ideas on why this is happening? Thanks.

noob
  • 5,954
  • 6
  • 20
  • 32
  • 3
    never delete items from a list you are iterating over (unless you **really** know what you are doing)! https://stackoverflow.com/questions/6500888/removing-from-a-list-while-iterating-over-it – hiro protagonist Nov 10 '19 at 14:42
  • ... unless you iterate over the list in _reverse_ order ... – snakecharmerb Nov 10 '19 at 14:43

0 Answers0