On 3/13/06, Jonathan Ellis <[EMAIL PROTECTED]> wrote: > #!/usr/bin/python2.4 > > import sys > > WORDS_FNAME = '/usr/share/dict/words' > words = dict((line.rstrip(), 0) for line in file(WORDS_FNAME)) > > source = len(sys.argv) > 1 and file(sys.argv[1]) or sys.stdin > for line in source: > for word in line.strip().split(): > if not word: > continue > try: > words[word] += 1 > except KeyError: > pass > > for word, count in words.iteritems(): > if count > 0: > print word, count
Much better! Python ------ LOC: 18 Best Time: 1.732 Worst Time: 2.767 Avg. Time: 2.09 /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
