Skip to content
Merged

0004 #228

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Huangyunbo1996/0001/GenerateActivationCode.py
Original file line number Diff line number Diff line change
@@ -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
#...
42 changes: 42 additions & 0 deletions Huangyunbo1996/0002/ActivationCode_MySql.py
Original file line number Diff line number Diff line change
@@ -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!')
131 changes: 131 additions & 0 deletions Huangyunbo1996/0004/Word_Statistics.py
Original file line number Diff line number Diff line change
@@ -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