mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-20 19:42:45 +08:00
psf/black code formatting (#1277)
This commit is contained in:

committed by
Christian Clauss

parent
07f04a2e55
commit
9eac17a408
@ -1,18 +1,21 @@
|
||||
import os
|
||||
|
||||
UPPERLETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
LETTERS_AND_SPACE = UPPERLETTERS + UPPERLETTERS.lower() + ' \t\n'
|
||||
UPPERLETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
LETTERS_AND_SPACE = UPPERLETTERS + UPPERLETTERS.lower() + " \t\n"
|
||||
|
||||
|
||||
def loadDictionary():
|
||||
path = os.path.split(os.path.realpath(__file__))
|
||||
englishWords = {}
|
||||
with open(path[0] + '/dictionary.txt') as dictionaryFile:
|
||||
for word in dictionaryFile.read().split('\n'):
|
||||
with open(path[0] + "/dictionary.txt") as dictionaryFile:
|
||||
for word in dictionaryFile.read().split("\n"):
|
||||
englishWords[word] = None
|
||||
return englishWords
|
||||
|
||||
|
||||
ENGLISH_WORDS = loadDictionary()
|
||||
|
||||
|
||||
def getEnglishCount(message):
|
||||
message = message.upper()
|
||||
message = removeNonLetters(message)
|
||||
@ -28,14 +31,16 @@ def getEnglishCount(message):
|
||||
|
||||
return float(matches) / len(possibleWords)
|
||||
|
||||
|
||||
def removeNonLetters(message):
|
||||
lettersOnly = []
|
||||
for symbol in message:
|
||||
if symbol in LETTERS_AND_SPACE:
|
||||
lettersOnly.append(symbol)
|
||||
return ''.join(lettersOnly)
|
||||
return "".join(lettersOnly)
|
||||
|
||||
def isEnglish(message, wordPercentage = 20, letterPercentage = 85):
|
||||
|
||||
def isEnglish(message, wordPercentage=20, letterPercentage=85):
|
||||
"""
|
||||
>>> isEnglish('Hello World')
|
||||
True
|
||||
@ -51,4 +56,5 @@ def isEnglish(message, wordPercentage = 20, letterPercentage = 85):
|
||||
|
||||
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
Reference in New Issue
Block a user