如何将[same] foo添加到字典的所有键中,以便
a = {'continent': ['America', 'South Africa'], 'country': ['USA', 'Egypt']}
变为:
a = {'foo(bar=continent, hello=world)': ['America', 'South Africa'], 'foo(bar=country, hello=world)': ['USA', 'Egypt']}
编辑: 我实际上是想将str键编辑为非str键,所以:
a = {foo(bar='continent', hello=world): ['America', 'South Africa'], foo(bar='country', hello=world): ['USA', 'Egypt']}
答案 0 :(得分:4)
a = {'foo(bar=' + key + ', hello=world)': a[key] for key in a.keys()}