Comment on Python: copying a list the right wayparentComments−d0mine14ylist.remove() returns None. So it is a mistake to bind its return value to allbut2.It follows the convention that methods that modify their object inplace should return None. list.pop() is an obvious exception.You create a new list via list comprehension instead of copying and then removing: even = [i for i in L if i % 2 == 0] # remove odd numbers−tedunangst14yI believe he meant: all = range() allbut2 = all allbut2.remove(2) which is something that catches people all the time.
Comments
list.remove() returns None. So it is a mistake to bind its return value to allbut2.
It follows the convention that methods that modify their object inplace should return None. list.pop() is an obvious exception.
You create a new list via list comprehension instead of copying and then removing:
I believe he meant:
which is something that catches people all the time.