0

My program uses this variable:

questionNum = random.randint(0,9)

Later in the program I tried to remove an element in the list by doing this:

questionList.remove([questionNum])

I got this error:

list.remove(x): x not in list

How can I remove an element in the list at the index questionNum?

Tonechas
  • 13,398
  • 16
  • 46
  • 80
Rachel FG
  • 9
  • 1
  • 2
    `list.remove(x)` searches for values, not indexes. `list.pop(index)` would do what you want. It's in the documentation. – Jean-François Fabre Dec 09 '16 at 14:18
  • 2
    Just as an FYI, a Google search with exactly the title of your question yielded some very good answers to this question. Please try searching before asking. – jarmod Dec 09 '16 at 14:27

1 Answers1

2

list.remove takes the element to remove, not the index. list.pop is what you want.

Be aware, though, that this decreases your list's size. So, if you pop the element at index 5, elements at index 6, 7, 8 etc are now in index 5, 6, 7 etc.

lucasnadalutti
  • 5,818
  • 1
  • 28
  • 48