【发布时间】:2014-10-14 09:05:32
【问题描述】:
鉴于以下字典,我如何返回从键中去除所有非数字的新键?
import re
dict {'abc_12': 5, 'abc_1': 7, 'abc_34': 10}
for k in dict:
re.sub('[^0-9]', '', k)
# change value of first key to '12': 5
【问题讨论】:
-
您不能有重复的密钥。你想如何处理这个问题?
标签: python regex python-3.x dictionary