我有一个像下面这样的构造,如何使用 1 个(或更多)列表推导来获得相同的输出?
f2remove = []
for path in (a,b):
for item in os.listdir(path):
if os.path.isdir(os.path.join(path,item)):
x = parse_name(item)
if x and (ref - x).days >= 0:
f2remove.append(os.path.join(path,item))
我尝试了多种方法,例如
files = [parse_name(item)\
for item in os.listdir(path) \
for path in (a,b)\
if os.path.isdir(os.path.join(path,item))] # get name error
f2remove = [] # problem, don't have path...
错误:
Traceback (most recent call last):
File "C:\Users\karuna\Desktop\test.py", line 33, in <module>
for item in os.listdir(path) \
NameError: name 'path' is not defined