【发布时间】:2017-04-23 18:02:44
【问题描述】:
所以我有一个 json 对象数组,看起来像:
data = [{key1: 123, key2:"this is the first string to concatenate"},
{key1: 131, key2:"this is the second string to concatenate"},
{key1: 152, key2:"this is the third string to concatenate"} ]
基本上,我现在使用的 for 循环如下:
all_key2 = ""
data = json.load(json_file)
for p in data:
#make it all one big string
if langid.classify(p["key2"])=="english":
all_key2 = p["key2"] + " " + all_key2
所以答案应该是:
"this is the first string to concatenate this is the second string to concatenate this is the third string to concatenate"
但这需要很多时间,因为我有大量的对象和长字符串。有没有更快的方法来完成这种连接?
[编辑] 正在研究lambda 函数,这可能是要走的路吗?
【问题讨论】:
标签: python json string python-3.x