ITeye博客

python challenge 3

he_lux · 2009-12-28 17:54 · python · 编程语言 · Markdown

第三题比较简单,One small letter, surrounded by EXACTLY three big bodyguards on each of its sides. 即一个小写字母,两边各有不多不少的三个大写字母。 用正则表达式搞定。


import re

if __name__ == '__main__':
    # put the mess from the page source into 3.txt 
    f = open('3.txt', 'r')
    text = f.read()
    
    list = re.findall('[^a-z][a-z]{3}[a-z][a-z]{3}[^a-z]', text)
    
    print(''.join(x[4:5] for x in list))
    
    f.close();

评论(1)

  1. #1 楼 · mdjhny · 2010-07-21 00:38

    正则得到列表后的处理很狡猾,我当时是老老实实再正则了一次

评论功能维护中,当前仅展示历史评论。