我想遍历并合并两个列表中的项目。但它必须从列表 1 中的第 1 项开始,遍历并与列表 2 中的所有项目组合。
partner_paths = ["/partner/path/1", "/partner/path/2", "/partner/path/3"]
scr_dirs = ["/dir1", "/dir2", "/dir3"]
for p_path, s_dir in zip(partner_paths, scr_dirs):
fpath = p_path + s_dir
print fpath
我想要的是:
“/合作伙伴/路径/1/dir1” “/伙伴/路径/1/dir2” “/伙伴/路径/1/dir3”
“/合作伙伴/路径/2/dir1” “/伙伴/路径/2/dir2” “/伙伴/路径/2/dir3”
“/合作伙伴/路径/3/dir1” “/伙伴/路径/3/dir2” “/伙伴/路径/3/dir3”
最佳答案
双 for
循环不是问题吗?
for p_path in partner_paths:
for s_dir in scr_dirs:
fpath = p_path + s_dir
print fpath
关于python - 遍历两个列表并组合项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42585736/