如何按元素 os.path.join 不均匀列表
how to os.path.join uneven lists element-wise
说我有
folders = [['folder1/subfold'],['folder2/subfold/subsubfold']]
clas = [['class1'], ['class2', 'class3','class4']]
如何将 类 的路径加入到它们各自的文件夹中?期望:
['folder1/subfold/class1',
'folder2/subfold/subsubfold/class2',
'folder2/subfold/subsubfold/class3',
'folder2/subfold/subsubfold/class4']
以下内容似乎仅在列表具有相同维度时才有效:[os.path.join(*i, j) for i,j in zip(folders, clas)]
你想要的是嵌套for循环
[os.path.join(*i, j) for i, names in zip(folders,clas) for j in names]
说我有
folders = [['folder1/subfold'],['folder2/subfold/subsubfold']]
clas = [['class1'], ['class2', 'class3','class4']]
如何将 类 的路径加入到它们各自的文件夹中?期望:
['folder1/subfold/class1',
'folder2/subfold/subsubfold/class2',
'folder2/subfold/subsubfold/class3',
'folder2/subfold/subsubfold/class4']
以下内容似乎仅在列表具有相同维度时才有效:[os.path.join(*i, j) for i,j in zip(folders, clas)]
你想要的是嵌套for循环
[os.path.join(*i, j) for i, names in zip(folders,clas) for j in names]