Example code:
found_list = [1,2,3,4,5]
remove_list =[1,2,3,4,5]
for canidate in found_list:
if canidate in remove_list:
found_list.remove(canidate)
# Expecting this to be an EMPTY list.
# because everything in found is in remove
print("NEW FOUND LIST: %s" % found_list )
In my actual case, I am using "os.walk()" - and need to prune/ignore some subdirectories. The example is a list of subdirectories (ie: names like: ".svn" and ".git") I want to ignore
The examples I have seen are to use for() over the directory or file list. And use list.remove() to remove the specific item directly.
However - things are not being deleted like I expect. I think this is a limitation (?bug?) in the way that the for() loop iterates over a list ie: If you delete the current item the next item is skipped and not considered.
Is this documented anywhere?
My workaround solution is to create a new list and then assign that to the list given by os.walk()
Thanks.