Skip to content

Instantly share code, notes, and snippets.

@paulohrpinheiro
Created August 22, 2015 20:58
Show Gist options
  • Save paulohrpinheiro/ff23cf9a43b381a69957 to your computer and use it in GitHub Desktop.
Save paulohrpinheiro/ff23cf9a43b381a69957 to your computer and use it in GitHub Desktop.
Primeira refatorado do programa.
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