binary search tress using classes

Fredrik Lundh fredrik at pythonware.com
Sun Oct 28 04:43:22 EST 2001


Terry Reedy wrote:
> The way to do this in Python is with a dictionary.  Without being
> fancy about the definition of 'word', you need 10 lines or less for
> the whole program.  I believe I've seen the code posted.

text = """
Have a nice day.  Have a nice day.
Have a nice day.
Have a nice day.
"""

import re

# count the words
count = {}
for word in re.findall("\w+", text.lower()):
    count[word] = count.setdefault(word, 0) + 1

# print the result
items = count.items()
items.sort()
for k, v in items:
    print k, v

> Using classes and 'modularity' is way overkill.

better tell that to her teacher ;-)

</F>





More information about the Python-list mailing list