Python application case

Source: Internet
Author: User

Generate Activation Code

#!/usr/bin/env Python#encoding:utf-8#author:seanimport Stringimport random# The characters and numbers in the Activation Code field = String.letters + string.digits# get four letters and numbers in a random combination def getrandom (): Return '. Join (Random.sample (field,4)) #生成的每个激活码中有几组def concatenate (gr OUP): Return '-'. Join ([Getrandom () for I in Range (group)]) #生成n组激活码def Generate (N): Return [CONCATENATE (4) for I In range (n)] if __name__ = = ' __main__ ': print Generate (10)

Statistical words

#!/usr/bin/env Python#encoding:utf-8import refrom Collections Import Counterfilesource = './media/abc.txt ' Def Getmostcommonword (Articlefilesource): "Enter an English plain text file that counts the number of occurrences of the word ' pattern = R ' [a-za-z]+|\$?\d+%?$ ' with open (  Articlefilesource) as F:r = Re.findall (Pattern,f.read ()) return Counter (R). Most_common () if __name__ = = ' __main__ ': Print Getmostcommonword (Filesource)

Extract page body

#!/usr/bin/env python#encoding:utf-8from Goose Import goosefrom goose.text import Stopwordschineseimport sys#  To parse the page Urlurl = ' def extract (URL): ' Extract the page body ' ' G = Goose ({' Stopwords_class ': Stopwordschinese}) Artlcle = G.extract (Url=url) return artlcle.cleaned_textif __name__ = = ' __main__ ': Print extract (URL)

This article is from the "Home" blog, please make sure to keep this source http://itchentao.blog.51cto.com/5168625/1899821

Python application case

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.