List to string? Docstrings?

François Pinard pinard at iro.umontreal.ca
Mon Sep 13 22:29:30 EDT 1999


Hi, people.

> >        text = reduce(operator.concat, chars)

Thanks for all the replies.  You all suggested:

> string.join(chars, '')

I benchmarked the reduce with operator.concat method, versus the string.join
method, and systematically in my tests, string.join is much faster, and
the improvement gets more noticeable as the character list size increases.

Thinking more about it, it seems quite reasonable to guess that the reduce
method shows a quadratic time behaviour in the list size, because of all
intermediary results, while string.join _may_ be implemented to use linear
time in the list size.  But I did not benchmark to check that hypothesis.


I also thank you for your remarks about doc strings.  I'm not sophisticated
enough in Python for docstrings to be really useful to me right now,
but I begin to understand that docstrings might be worth in the long run.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list