Today I am going to explain a small piece of code to remove items from a list.
Let's say
I'm iterating over a list of tuples in Python, and am attempting to remove them if they meet certain criteria.
What should I use in place of code_to_remove_tup?
A list comprehension is best for this kind of loop.
If I want to 'determine' what should be deleted. That would then be just.
EDIT: The above would create a new list and assign it the name of old list. So, you will loose reference to the original list unless you do it this way,This is explained in List slicing(One of my previous posts)
Also, using itertools(explained in a previous post). However there is no non iterator filterfalse, so it will have to be.
Written by Vivek Soundrapandi
Published Date: {{ article.pub_date }}
View all posts by: Vivek Soundrapandi