我想遍历并合并两个列表中的项目。但它必须从列表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


我想要的是:

“ / partner / path / 1 / dir1”
“ / partner / path / 1 / dir2”
“ / partner / path / 1 / dir3”

“ / partner / path / 2 / dir1”
“ / partner / path / 2 / dir2”
“ / partner / path / 2 / dir3”

“ / partner / path / 3 / dir1”
“ / partner / path / 3 / dir2”
“ / partner / path / 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/

10-10 13:09