我有一本字典。
prices = {'n': 99, 'a': 99, 'c': 147}
Run Code Online (Sandbox Code Playgroud)
使用map()我需要接收新的字典:
def formula(value):
value = value -value * 0.05
return value
Run Code Online (Sandbox Code Playgroud)
new_prices = dict(map(formula, prices.values()))
Run Code Online (Sandbox Code Playgroud)
但它不起作用
TypeError: cannot convert dictionary update sequence element #0 to a sequence
Run Code Online (Sandbox Code Playgroud)
使用以下方法解决我的代码map():
new_prices = {'n': 94.05, 'a': 94.05, 'c': 139.65}
Run Code Online (Sandbox Code Playgroud)