我有一个字符串列表,我想将它们组合在一起。
list = ["name", "lastname", "year"]
var = ''.join(list)
print(list)
我希望输出为:
nameyear
lastnamename
lastnameyear
yearname
yearlastname
答案 0 :(得分:0)
尝试一下:
words = ["name", "lastname", "year"]
for i, word1 in enumerate(words):
for j, word2 in enumerate(words):
if i != j:
print(word1 + word2)
输出:
namelastname
nameyear
lastnamename
lastnameyear
yearname
yearlastname
此外,不要使用list
作为变量名,因为它是python关键字。