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.

时间: 2024-10-03 17:11:57

pychallenge(3)-re的相关文章

pychallenge(4)-follow the chain

pychallenge之四 <!-- urllib may help. DON'T TRY ALL NOTHINGS, since it will never end. 400 times is more than enough. --> 点图片跳出了:and the next nothing is 44827,看起来似乎是嵌套的网页 # -*- coding: utf-8 -*- import requests import re import time class NothingExcep