+ -
当前位置:首页 → 问答吧 → python中的dict数据结构是怎么查询的,hash?

python中的dict数据结构是怎么查询的,hash?

时间:2011-09-03

来源:互联网

http://www.pythonchallenge.com/pc/def/ocr.html
下面是python chanllenge第二关的解法,
>>> import urllib
>>> def get_challenge(s): return urllib.urlopen('http://www.pythonchallenge.com/pc/' + s).read()
...
>>> src = get_challenge('def/ocr.html')
>>> import re
>>> text = re.compile('<!--((?:[^-]+|-[^-]|--[^>])*)-->', re.S).findall(src)[-1]
>>> counts = {}
>>> for c in text: counts[c] = counts.get(c, 0) + 1
>>> counts
{'\n': 1221, '!': 6079, '#': 6115, '%': 6104, '$': 6046, '&': 6043, ')': 6186, '(': 6154,
'+': 6066, '*': 6034, '@': 6157, '[': 6108, ']': 6152, '_': 6112, '^': 6030, 'a': 1,
'e': 1, 'i': 1, 'l': 1, 'q': 1, 'u': 1, 't': 1, 'y': 1, '{': 6046, '}': 6105}

上面text = re.compile('<!--((?:[^-]+|-[^-]|--[^>])*)-->', re.S).findall(src)[-1]这句话中的
'<!--((?:[^-]+|-[^-]|--[^>])*)-->' 不太理解,,这个正则表达式,是要匹配些什么?
网页:http://www.pythonchallenge.com/pc/def/ocr.html

作者: bellszhu   发布时间: 2011-09-03

头疼...这个正则,上次我就是用最简单的替换来搞定的

作者: leeaman   发布时间: 2011-09-03