From 7b2c53efaf5ab08251d5da9ff1fa842303837dbd Mon Sep 17 00:00:00 2001 From: Hyb Date: Wed, 15 Mar 2017 21:41:20 +0800 Subject: [PATCH 1/3] 0004 --- Huangyunbo1996/0004/Word_Statistics.py | 131 +++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Huangyunbo1996/0004/Word_Statistics.py diff --git a/Huangyunbo1996/0004/Word_Statistics.py b/Huangyunbo1996/0004/Word_Statistics.py new file mode 100644 index 00000000..bbd8c7ce --- /dev/null +++ b/Huangyunbo1996/0004/Word_Statistics.py @@ -0,0 +1,131 @@ +#-*-coding:utf-8-*- +import os +import re + +def word_statistics(filePath): + wordDict = {} + with open(filePath,'rt') as f: + for line in f: + words = re.split('[,.\s]\s*',line) + for word in words: + if word.lower() in wordDict and word.isalpha(): + wordDict[word.lower()] += 1 + elif word.lower() not in wordDict and word.isalpha(): + wordDict[word.lower()] = 1 + + wordSorted = sorted(zip(wordDict.keys(),wordDict.values())) + + for word,count in wordSorted: + print(word,':',count) + +if __name__ == '__main__': + word_statistics(r'...\test.txt') + +#output: +# a : 11 +# about : 1 +# access : 1 +# algorithm : 1 +# allowing : 3 +# allowingwith : 1 +# alone : 4 +# an : 2 +# and : 1 +# anything : 1 +# are : 1 +# as : 3 +# attribute : 1 +# attributes : 6 +# calling : 1 +# calls : 1 +# can : 6 +# case : 1 +# change : 1 +# class : 4 +# code : 5 +# complicated : 4 +# control : 1 +# creates : 1 +# defining : 1 +# definition : 1 +# do : 4 +# drive : 1 +# easily : 1 +# easy : 5 +# etc : 1 +# everything : 4 +# expose : 1 +# extra : 2 +# fact : 1 +# fall : 4 +# for : 6 +# forget : 1 +# function : 6 +# functions : 4 +# generator : 8 +# generators : 4 +# going : 1 +# history : 1 +# how : 1 +# however : 1 +# if : 7 +# implement : 1 +# in : 6 +# instance : 1 +# interact : 5 +# internal : 1 +# into : 4 +# is : 6 +# it : 9 +# iteration : 1 +# just : 1 +# lead : 4 +# like : 1 +# loop : 1 +# makes : 1 +# method : 5 +# methods : 1 +# might : 1 +# needs : 4 +# normal : 1 +# of : 10 +# one : 1 +# or : 1 +# other : 5 +# part : 1 +# parts : 4 +# potential : 1 +# program : 4 +# provide : 1 +# putting : 1 +# rather : 4 +# require : 1 +# shown : 2 +# since : 1 +# solution : 1 +# state : 1 +# step : 1 +# subtlety : 1 +# such : 1 +# technique : 1 +# than : 1 +# that : 3 +# the : 13 +# this : 6 +# to : 22 +# trap : 4 +# treat : 1 +# trying : 4 +# unusual : 4 +# use : 2 +# user : 1 +# users : 1 +# using : 1 +# via : 1 +# want : 1 +# ways : 4 +# with : 13 +# would : 1 +# write : 1 +# you : 7 +# your : 6 From 0f06bc70a8b4be5e269e9627683414e1f490dc19 Mon Sep 17 00:00:00 2001 From: Hyb Date: Wed, 15 Mar 2017 22:07:39 +0800 Subject: [PATCH 2/3] 0001 --- Huangyunbo1996/0001/GenerateActivationCode.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Huangyunbo1996/0001/GenerateActivationCode.py diff --git a/Huangyunbo1996/0001/GenerateActivationCode.py b/Huangyunbo1996/0001/GenerateActivationCode.py new file mode 100644 index 00000000..7e0169b1 --- /dev/null +++ b/Huangyunbo1996/0001/GenerateActivationCode.py @@ -0,0 +1,29 @@ +#-*- coding:utf-8 -*- +import uuid +from itertools import dropwhile + +def generateActivationCode(num): + codeList = [] + for i in range(num): + code = str(uuid.uuid4()).replace('-','').upper() + while code in codeList: + code = str(uuid.uuid4()).replace('-','').upper() + codeList.append(code) + + for code in codeList: + print(code) + +if __name__ == '__main__': + generateActivationCode(200) + +#output +# 4A5C6F8482544BA8B61F26945E8DA6CA +# 002751306CA34E798BE492379F14F09B +# AD2FD3F1C5CC4769AA3C9FF1D9247C77 +# BB9BB4D6B4AC490A800929B7ABA0CF48 +# 28F0A9E062964313B36556A6D4B62753 +# 1C5D17EF07FC484B8DADB15FAC0D9BB5 +# AC2146D68BA34199B75ACC727D2B017D +# 64866B2136C641DA956A3A52274DA3E0 +# F00DDD20295C4E2CBDC8E62A0C72AABC +#... \ No newline at end of file From 1817ce6b90e634d3ef4450d9de2bfbf01aef07b9 Mon Sep 17 00:00:00 2001 From: Hyb Date: Wed, 15 Mar 2017 22:38:15 +0800 Subject: [PATCH 3/3] 0002 --- Huangyunbo1996/0002/ActivationCode_MySql.py | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Huangyunbo1996/0002/ActivationCode_MySql.py diff --git a/Huangyunbo1996/0002/ActivationCode_MySql.py b/Huangyunbo1996/0002/ActivationCode_MySql.py new file mode 100644 index 00000000..bcca6548 --- /dev/null +++ b/Huangyunbo1996/0002/ActivationCode_MySql.py @@ -0,0 +1,42 @@ +#-*- coding:utf-8 -*- +import uuid +import pymysql + +def generateActivationCode(num): + codeList = [] + for i in range(num): + code = str(uuid.uuid4()).replace('-','').upper() + while code in codeList: + code = str(uuid.uuid4()).replace('-','').upper() + codeList.append(code) + + return codeList + +def storeInMysql(codelist): + try: + conn = pymysql.connect(host='127.0.0.1',user='root',passwd='root',db='mysql') + cur = conn.cursor() + except BaseException as e: + print(e) + else: + try: + cur.execute('CREATE DATABASE IF NOT EXISTS activation_code') + cur.execute('USE activation_code') + cur.execute('''CREATE TABLE IF NOT EXISTS code( + + id INT NOT NULL AUTO_INCREMENT, + code VARCHAR(32) NOT NULL, + PRIMARY KEY(id) + )''') + for code in codelist: + cur.execute('INSERT INTO code(code) VALUES(%s)',(code)) + cur.connection.commit() + except BaseException as e: + print(e) + finally: + cur.close() + conn.close() + +if __name__ == '__main__': + storeInMysql(generateActivationCode(200)) + print('OK!') \ No newline at end of file