Created
November 3, 2017 14:49
-
-
Save pelid/fc74095b3b1e9370101650801664dff1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
import re | |
import timeit | |
def remove_unwanted_symbols_1(text): | |
test_list = [] | |
for symbol in text.lower(): | |
if symbol in string.ascii_letters: | |
test_list.append(symbol) | |
return ''.join(test_list) | |
def remove_unwanted_symbols_2(text): | |
test_list = [] | |
for symbol in text.lower(): | |
if symbol == "-" or symbol == "`": | |
continue | |
test_list.append(symbol) | |
return ''.join(test_list) | |
def remove_unwanted_symbols_3(text): | |
test_list = [] | |
for symbol in text.lower(): | |
if symbol.isalpha(): | |
continue | |
test_list.append(symbol) | |
return ''.join(test_list) | |
if __name__ == '__main__': | |
with open('lorem.txt') as f: | |
text = f.read() | |
print('Letters count is', len(text)) | |
print(timeit.Timer(lambda: remove_unwanted_symbols_1(text)).timeit(number=5)) | |
print(timeit.Timer(lambda: remove_unwanted_symbols_2(text)).timeit(number=5)) | |
print(timeit.Timer(lambda: remove_unwanted_symbols_3(text)).timeit(number=5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Результат вычислений на моей машине:
Вывод: дело не в isalpha