Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7948

Re: NEED HELP-process words in a text file

From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: NEED HELP-process words in a text file
Date 2011-06-19 11:45 +0200
References <BANLkTinjLGSim79f1acOKzYgUq5xoSFdeg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.142.1308476721.1164.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: NEED HELP-process words in a text file Stefan Behnel <stefan_ml@behnel.de> - 2011-06-19 11:45 +0200

csiph-web