Pychallenge (3)-re, pychallenge-re

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.