У меня есть такой словарь (на самом деле это json):
[
{
"val": "regards",
"example": ["kind regards","regards", "kind regards"]
},
{
"val": "Greets",
"example": ["Hello ","Hi","Hello", "Hello"]
}
]
Как удалить дублирующиеся строки в ключе example
?Я пытался:
In:
def remove_dups(a_dict):
return {k:sorted(set(j),key=j.keys) for k,j in a_dict.items()}
with open('../a_json.json','r') as fa:
a = json.load(fa)
pprint(list(map(remove_dups,a)))
Out:
[
{
"val": ['r','e','g','a','r','d','s'],
"example": ["regards", "kind regards"]
},
{
"val": ['G','r','e','e','t','s'],
"example": ["Hi","Hello"]
}
]
Тем не менее, ключ val
преобразуется в список строк.Как я могу оставить val
и просто удалить дубликаты из example
?