我有 14 个字典,它们都包含相同的信息键,但值不同。我正在尝试构建一个函数,当字典被列为函数中的参数时,它将组合一个句子。
错误是:
TypeError: can only concatenate list (not "str") to list
这是代码:
def createhouses(x):
count = 0
for i in [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14]:
i["sn"] = legendary[count]
i["fn"] = [legendaryfn[count]]
i["family"] = [hProfession[random.randint(0, len(hProfession)-1)]]
i["house"] = [houseGen()]
i["fortune"] = [prosperity[random.randint(0, len(prosperity)-1)]]
i["tort"] = random.randint(0, 1)
count+=1
createhouses(1)
以及引发错误的代码:
def houseHistory(x):
print x['fn']+" "+x['sn']