3 ms·
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 sho
by d0mine 15y ago
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:
even = [i for i in L if i % 2 == 0] # remove odd numbers
- tedunangst 15y agoI believe he meant: all = range() allbut2 = all allbut2.remove(2) which is something that catches people all the time.