1

i have a list like below:

myList = [3, 5, 7, 2, 100, 76]

I want to delete all the elements from the list starting with the element 2, i.e., after deletion the list should like this:

myList = [3, 5, 7]

How can I do that? There's no duplicate elements in the list.

Debbie
  • 911
  • 3
  • 20
  • 45

1 Answers1

4

Do you mean something like this

>>> myList = [3, 5, 7, 2, 100, 76]
>>> myList.index(2)
3
>>> myList[:myList.index(2)]
[3, 5, 7]
>>> 


ex4
  • 2,289
  • 1
  • 14
  • 21