[英]How to get input from user to find a key within a dicitionary and output its value?
[英]How to get a dicitionary key value from a string that contains dictionary?
我有一个包含字典的字符串:
data = 'IN.Tags.Share.handleCount({"count":17737,"fCnt":"17K","fCntPlusOne":"17K","url":"www.test.com\\/"});'
如何获得字典元素count
值? (以我为例17737)
PS也许我需要从字符串中删除IN.Tags.Share.handleCount
,然后再通过k = data.replace("IN.Tags.Share.handleCount", "")
获取字典,但是'()'
之后仍然存在的问题删除?
谢谢
import re, ast
data = 'IN.Tags.Share.handleCount({"count":17737,"fCnt":"17K","fCntPlusOne":"17K","url":"www.test.com\/"});'
m = re.match('.*({.*})', data)
d = ast.literal_eval(m.group(1))
print d['count']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.