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.
>Solution :
Do you mean something like this
>>> myList = [3, 5, 7, 2, 100, 76]
>>> myList.index(2)
3
>>> myList[:myList.index(2)]
[3, 5, 7]
>>>