Pychallenge (3)-re, pychallenge-re
Pychallenge 3
The question is illustrated in the following figure.
One small letter, surroundedEXACTLYThree big bodyguards on each of its sides.
On paper, it means that a lowercase letter is surrounded by three big guys on both sides. The bold EXACTLY indicates that only three are allowed,
It cannot be more or less. As before, you can see a text section on the webpage source. The Code is as follows:
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 ')
The running result is as follows:
C: \ Python27 \ python.exe D:/Py/test. py
['L', 'I', 'n', 'k', 'E', 'D', 'l', 'I', 's', 't']
The combination should be sorted list.