将字符串连接到python中的词典列表

将字符串连接到python中的词典列表,python,python-3.x,list,dictionary,concatenation,Python,Python 3.x,List,Dictionary,Concatenation,我正在尝试将一个字符串加入字典列表。我正在做: print(site + ', '.join(search_res)) 我一直收到一个错误:序列项0:预期的str实例,dict found search_res = [ { "book": "Harry Potter", "rating": "10.0" }, { "book": "Lord of The Rings", "rating": "9.0"

我正在尝试将一个字符串加入字典列表。我正在做:

print(site + ', '.join(search_res))
我一直收到一个错误:
序列项0:预期的str实例,dict found

search_res = [
    {
        "book": "Harry Potter",
        "rating": "10.0"
    },
    {
        "book": "Lord of The Rings",
        "rating": "9.0"
    }
]

site = "Fantasy"
预期结果:

"Fantasy" , [
    {
        "book": "Harry Potter",
        "rating": "10.0"
    },
    {
        "book": "Lord of The Rings",
        "rating": "9.0"
    }
]
如何将字符串连接到字典列表,而不获取序列项0:expected str instance,dict founderror

为什么不直接打印(site+str(search_res))

你也可以这样做:
print(site+,”。加入([str(dic)代表搜索中的dic)]
也许你只需要这个:
print(site+,“+str(search_res))

如何将字符串连接到字典列表


你不能。你也不需要。可能与一起使用。

您的预期结果是什么?字符串、dict或元组?此
[site]+search\u res
?传递给
join
的参数项不能是字典;它们必须是字符串。。这就是错误告诉您的。你想做什么?为什么?