How to remove a particular item in a list by its index? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

How to remove a particular item in a list by its index?

Lets say we have a list ["1","2","2","3"]. I know the location of 3 and i want to remove the object just before it i.e. "2". We can't use remove method here as it takes only one input that is the object you want to remove and it removes the first of that kind and not all. I want to particularly remove the second 2. How can i do that?

23rd Sep 2022, 12:16 PM
Abhay Kumar
Abhay Kumar - avatar
1 Answer
+ 4
Abhay Kumar , we can use del. the syntax is: del <iterable name>[<index>]
23rd Sep 2022, 12:24 PM
Lothar
Lothar - avatar