我有一本字典dict
:
dict = {'drop_key1': '10001', 'drop_key2':'10002'}
dict
startwith 中的键drop_
,我想dict
通过drop_
从键中删除值来更新:
dict = {'key1': '10001', 'key2':'10002'}
最好的方法是什么?
就像是
d1 = {'drop_key1': '10001', 'drop_key2':'10002'}
d2 = {k[5:]:v for k,v in d1.items()}
print(d2)
输出
{'key1': '10001', 'key2': '10002'}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句