Python Challenge 0~2

Source: Internet
Author: User

Section o off

Using Python to calculate 2 * * 38, replace the URL to

1th Pass

Really covered, and finally Google a bit, only to understand that all the letter displacement >> two-bit

Import= Str.maketrans ('abcdefghijklmnopqrstuvwxyz','  Cdefghijklmnopqrstuvwxyzab')print("'g fmnc wms Bgblr RPYLQJYRC GR ZW fylb. RFYRQ Ufyr AMKNSRCPQ ypc DMP. Bmgle GR GL ZW fylb GQ glcddgagclr ylb rfyr ' q UFW rfgq rcvr GQ QM Jmle. Sqgle QRPGLE.KYICRPYLQ () GQ PCAMKKCLBCB. LMU ynnjw ml RFC spj. ". Translate (trans))

Learning function:

Maketrans (str1, str2) make a conversion table that converts the letter one by one in str1 to the letter in the str2 corresponding position

Translate (trans) converting strings using conversion tables

2nd Pass

Look directly to the source file interface

The original is counting AH.

>>> fromUrllibImport*>>> fromUrllib.requestImport*>>> res = Urlopen ('http://www.pythonchallenge.com/pc/def/ocr.html')>>>ImportRe>>> template = Re.compile ('<!--. *?-->', Re. Dotall)>>> A =re.findall (template, Res.read (). Decode ())>>> fromCollectionsImportCounter>>> Counter (a[1]) Counter ({')': 6186,'@': 6157,'(': 6154,']': 6152,'#': 6115,'_': 6112,'[': 6108,'}': 6105,'%': 6104,'!': 6080,'+': 6066,'$': 6046,'{': 6046,'&': 6043,'*': 6034,'^': 6030,'\ n': 1221,'-': 4,'a': 1,'T': 1,'I': 1,'L': 1,'<': 1,'y': 1,'>': 1,'u': 1,'e': 1,'Q': 1})

It's kind of interesting.

Because the HTML is too large, I open it directly with Urlopen () and then take the regular expression out of that part (of course, in order to show the superiority of the regular expression found a ' <!--. *?--> ' match pattern, will match two strings out, the second string is asked, can be compared to HTML), Next follow the hint to find the least number of things. Ignore the <!---->.

A, T, I, L, y, u, E, q

And then he was blindfolded. What is this xxoo? Put it directly in the URL and put it in 404 after sorting.

English residue. It turned out to be equality. (Baidu's)

Learning function:

Urlopen (URL): Receive a html/equivalent to open a file, the operation is almost consistent

Compile (pattern, flag): Compile a regular expression matching string, speed up the use of multiple times, flag is used to adjust the matching pattern, for example, we need to use Dotall. Match \ n to match.

Counter (obj): Can be a string, list,tuple, and so on, returning a dict that contains the number of occurrences of all elements.

Python Challenge 0~2

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.