【发布时间】:2020-11-26 07:05:28
【问题描述】:
这是我合并三个列表的代码。
one=['nlo_90', 'nhi_76', 'nhi_88']
two=['12', '44', '84']
three=[['a','a','b','c'], ['g','a','g','g'], ['b','g','g','b']]
new_three=[list(dict.fromkeys(q)) for q in three]
z=zip(one,two,new_three)
for a,b,c in z:
print(f'a:{a},\tb:{b},\tc:{c}')
下面是输出:
a:nlo_90, b:12, c:['a', 'b', 'c']
a:nhi_76, b:44, c:['g', 'a']
a:nhi_88, b:84, c:['b', 'g']
我想要的输出是:
a:nlo_90, b:12, c:a, b, c
a:nhi_76, b:44, c:g, a
a:nhi_88, b:84, c:b, g
【问题讨论】:
-
", ".join(c)? -
不是您要求的,但考虑使用
set而不是您的 dict 方法从three中删除重复项。new_three = [set(q) for q in three]. -
从组件部分构建字符串可从任何有关字符串的教程中获得。我们希望您在此处发布之前进行基础研究。你在哪里被这些材料困住了?