From cfa9b65a96f99fab5a379d7a703efc6fafe0dc3c Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 13 Dec 2022 19:01:44 +0800 Subject: [PATCH] perf: enhance characters check --- src/punctuation/character.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/punctuation/character.py b/src/punctuation/character.py index 493479b..954d275 100755 --- a/src/punctuation/character.py +++ b/src/punctuation/character.py @@ -39,20 +39,34 @@ def toUnicode(character: str) -> int: # get unicode number def showCharacters(characters: list) -> None: # show character stat + letter = [] chinese = [] punctuation = [] + + def asciiRange(start: str, end: str) -> list: + return list(range(ord(start), ord(end) + 1)) + for c in characters: - if int('4E00', 16) < toUnicode(c) < int('9FA5', 16): # chinese unicode range + if int('4E00', 16) <= toUnicode(c) <= int('9FA5', 16): # chinese unicode range chinese.append(c) + elif toUnicode(c) in ( # numbers and letters + asciiRange('0', '9') + asciiRange('a', 'z') + asciiRange('A', 'Z') + ): + letter.append(c) else: punctuation.append(c) + print('\n\033[0;32mPunctuations\033[0;39m\033[0;35m(%d)\033[0;39m\n%s\n' % ( - len(punctuation), ' '.join(['`\033[0;33m%s\033[0;39m`' % p for p in punctuation]) + len(punctuation), '|'.join(['[\033[0;33m%s\033[0;39m]' % p for p in punctuation]) )) + + print('\033[0;32mLetters\033[0;39m\033[0;35m(%d)\033[0;39m' % len(letter)) + print(' '.join(['\033[0;31m%s\033[0;39m' % c for c in letter]) + '\n') + print('\033[0;32mChinese\033[0;39m\033[0;35m(%d)\033[0;39m' % len(chinese)) for i in range(0, len(chinese)): print('\033[0;36m%s\033[0;39m%s' % ( - chinese[i], '\n' if i % 64 == 63 else '' + chinese[i], '\n' if i % 60 == 59 else '' ), end = '') print('\n')