设为首页 加入收藏

TOP

pychallenge(3)-re
2017-10-09 17:34:07 】 浏览:3244
Tags:pychallenge -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.

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇deque双向队列 下一篇转:在 Ubuntu 上使用 Nginx 部署..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目