I am confuse about the behaviour of the filter function in Python 3.x assuming the next code:
>>> test = [1, 2, 3, 4, 5, 6, 7, 8]
>>> for num in range(4):
test = filter( lambda x: x != num, test)
>>> print(list(test))
# [1, 2, 4, 5, 6, 7, 8]
I was thinking that the test variable will contain the result of successively filtering the values (num) present in range(4), nevertheless the final list is not filtered at all !.
Can someone explain to me this behavior, please? And if possible how to get the expected result # [4, 5, 6, 7, 8]
Note: My original code isn't so simple as this one, but this is just to illustrate the point where I found my bug.