Created
August 22, 2015 20:58
-
-
Save paulohrpinheiro/ff23cf9a43b381a69957 to your computer and use it in GitHub Desktop.
Primeira refatorado do programa.
This file contains hidden or 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 sys | |
def distrincha(): | |
words = set() | |
plain_text = list() | |
codded_text= list() | |
# need for speed | |
_words_add = words.add | |
_codded_text_append = codded_text.append | |
# read content | |
plain_text = [l.strip().split() for l in sys.stdin] | |
# build a word list from content | |
for line in plain_text: | |
[_words_add(w) for w in line] | |
# set() don't have an index method, then use a list | |
words = list(words) | |
# need for speed | |
_words_index = words.index | |
# build codded content | |
for line in plain_text: | |
_codded_text_append([_words_index(w) for w in line]) | |
# how many words? | |
return len(words) | |
print('Total of words:', distrincha()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment