[Shootout-list] cleaner python word count

kosh kosh@aesaeion.com
Sat, 26 Mar 2005 03:35:09 -0700


The speed seems to be unchanged from what I can see compared to the one used 
on the site now but it is shorter and simpler I think.


import sys

def main():
    nl = nw = nc = 0

    for line in sys.stdin:
        nl += 1
        nc += len(line)
        nw += len(line.split())

    print "%d %d %d" % (nl, nw, nc)

main()