首页 > 代码库 > pychallenge(3)-re

pychallenge(3)-re

pychallenge之三

题目还是下面一幅图配上一段话。

技术分享

One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.

纸面意思是一个小写字母被两边各三个大家伙包围着,其中着重加粗的EXACTLY表明只能正好是三个,

不能多也不能少。和之前一样看网页source发现一段文字,代码如下:

 1 # -*- coding: utf-8 -*-
 2 import re
 3 
 4 def findwk(file):
 5     """
 6     :type file: str
 7     :rtype: list
 8     """
 9     result = []
10     with open(file) as f:
11         cont = f.read()
12         result = re.findall([^A-Z][A-Z]{3}[a-z][A-Z]{3}[^A-Z], cont)
13 
14     return [word[4] for word in result]
15 
16 if __name__ == __main__:
17     print findwk(C:\Users\Katsu\Desktop\pych3.txt)

运行结果得:

C:\Python27\python.exe D:/Py/test/test.py
[‘l‘, ‘i‘, ‘n‘, ‘k‘, ‘e‘, ‘d‘, ‘l‘, ‘i‘, ‘s‘, ‘t‘]

组合下应该是linkedlist.

 

pychallenge(3)-re