Want to traverse each element from below list one by one in next for loops.
How should i do it? how can i fit in one more for loop in it.
currently i am calling accessing summaryList[1] only one element
summaryList=['hi','bye','hello']
def list(path):
result = []
for root, dirs, files in os.walk(path):
for name in files:
if fnmatch.fnmatch(name, summaryList[1] '.txt'):
result.append(os.path.join(root, name))
CodePudding user response:
Use any()
:
if any(fnmatch(name, prefix '.txt') for prefix in summaryList):
CodePudding user response:
maybe something like this
if os.path.splitext(name)[0] in summaryList:
should work, fnmatch here seems not very usefull