Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Viewing all articles
Browse latest Browse all 9596

pychallenge(3)-re

$
0
0

pychallenge之三

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


pychallenge(3)-re

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.


Viewing all articles
Browse latest Browse all 9596

Trending Articles