NEED HELP-process words in a text file

Stefan Behnel stefan_ml at behnel.de
Sun Jun 19 05:45:02 EDT 2011


Cathy James, 19.06.2011 01:21:
> def fileProcess(filename):
>      """Call the program with an argument,
>      it should treat the argument as a filename,
>      splitting it up into words, and computes the length of each word.
>      print a table showing the word count for each of the word lengths
> that has been encountered.
>      Example:
>      Length Count
>      1 16
>      2 267
>      3 267
>      4 169
>      >>>"&"
>      Length    Count
>      0    0
>      >>>
>      >>>"right."
>      Length    Count
>      5    10
>      """

Note that ">>>" is commonly used in docstrings to implement doctests. That 
is, it should represent the beginning of a line (or more) of executable 
Python code, followed by the expected output for that code.

Example:

     def add(x,y):
         """Add two numbers.

         >>> 1+1
         2
         >>> add(1,1)
         2
         >>> add(1,1) == 1+1
         True
         """
         return x+y

http://docs.python.org/library/doctest.html

Stefan




More information about the Python-list mailing list