📅  最后修改于: 2022-03-11 14:46:38.526000             🧑  作者: Mango
# For a regular dict
mydict[k_new] = mydict.pop(k_old)
# To preserve ordering
d = {0:0, 1:1, 2:2, 3:3}
{"two" if k == 2 else k:v for k,v in d.items()}
# => {0: 0, 1: 1, 'two': 2, 3: 3}