newbie - infinite loop

Terry Reedy tjreedy at udel.edu
Mon Mar 19 16:22:58 CET 2001


Use a dictionary, not a list, to compile a 'list' of unique words.

words = {}
for word in text:
  if not hasattr(words, word):
    words[word] = None
wordlist = words.keys()

With only a little more effort and use of words.setdefault(), you can
easily count occurences.
Code recently posted.

Terry J. Reedy





More information about the Python-list mailing list