How to remove all elements from a list after specific index in Python

1 Answer

0 votes
lst = ["python", "java", "c++", "c", "c#", "javascript"]
 
index = lst.index('c')

lst = lst[:index]

print(lst)  
 
 
 
 
'''
run:
 
['python', 'java', 'c++']
 
'''

 



answered Jul 21, 2022 by avibootz
...