I was wondering what is the most pythonic way:
With a list of strings and a list of substrings, delete the items in the list of strings containing any of the subscripts.
list_dirs = ('C:\\foo\\bar\\hello.txt', 'C:\\bar\\foo\\.world.txt', 'C:\\foo\\bar\\yellow.txt') unwanted_files = ('hello.txt', 'yellow.txt)
Required Conclusion:
list_dirs = (C:\\bar\\foo\.world.txt')
I tried to implement similar questions such as this , but I am still trying to do the deletion and extend this specific implementation to a list.
So far I have done this:
for i in arange(0, len(list_dirs)): if 'hello.txt' in list_dirs[i]: list_dirs.remove(list_dirs[i])
This works, but it's probably not a cleaner way and, more importantly, it doesn't support the list, if I want to remove hello.txt or yellow.txt, I have to use a or. Thanks.
dudas source share