There are similar questions to this but not quite what im looking for.
Having created a list with all files from a specific path im looking to filter out anything that does not contain a specific sequence in a string.
def filter():
someFiles = os.listdir(somePath)
listSize = len(someFiles)
for i in range(0, listSize):
if (".py" not in someFiles):
someFiles.remove(i)
print("{0}".format(someFiles))
Im aware i shouldn't be modifying the size of a list through a loop but i left it just to roughly give an idea of what i'm trying to accomplish
I did not make it clear, the issue that im facing is that i'm not sure what approach i should be taking when trying to remove every element that does not contain ".py". What I wrote above is more of a rough draft.
files = [f for f in someFiles if ".py" not in f]if ".py" in f(note that OP removes the files that don't have'.py'in them).