Howegrown wordcount
David Wilson
dw at botanicus.net
Fri Jun 11 14:38:47 EDT 2004
On Fri, Jun 11, 2004 at 11:05:32AM -0700, Thomas Philips wrote:
> I've coded a little word counting routine that handles a reasonably
> wide range of inputs. How could it be made to cover more, though
> admittedly more remote, possibilites such as nested lists of lists,
> items for which the string representation is a string containing lists
> etc. etc. without significantly increasing the complexity of the
> program?
Hello,
Such 'magical' behaviour is error prone and causes many a headache when
debugging. Some might think that even this is too much:
> #Treat iterable inputs differently
> if "__iter__" in dir(input):
> wordList =(" ".join([str(item) for item in input])).split()
> else:
> wordList = [str(input)]
Myself included. Perhaps instead of increasing the complexity of this
function, why not write a few wrapper functions if you have the need.
David.
--
"Science is what we understand well enough to explain to a
computer. Art is everything else we do."
-- Donald Knuth
More information about the Python-list
mailing list