一定要问聪明人
https://codereview.stackexchange.com/
,但作为一个快速修复方法,您可以
map()
你对字典列表的转换功能如下:
def clean_text(value: str)-> str:
# ...
return value.replace("bad", "good")
def clean_dict(d: dict):
return {k:clean_text(v) for k,v in d.items()}
json_data = [
{"key1":"some bad",
"key2":"bad things",
"key3":"extra bad"},
{"key1":"more bad stuff",
"key2":"wow, so much bad",
"key3":"who dis?"},
# a few million more dictionaries
{"key1":"so much bad stuff",
"key2":"the bad",
"key3":"the more bad"},
]
x = list(map(clean_dict, json_data))
total
柜台,但好像从来没有离开过
get_json_data_clean()
无论如何。
不知道为什么@Daniel Gale提议
filter()