How to remove specific element by index from a list in Python

1 Answer

0 votes
lst = [4, 3, 6, 8, 1, 2, 7, 9, 5]
 
print(lst)
 
idx = 2
lst.pop(idx)  
print(lst)
 
idx = 2
lst.pop(idx)  
print(lst)
 
 
 
'''
run:
 
[4, 3, 6, 8, 1, 2, 7, 9, 5]
[4, 3, 8, 1, 2, 7, 9, 5]
[4, 3, 1, 2, 7, 9, 5]
 
'''

 



answered Jan 24, 2020 by avibootz
...