Naive idiom questions
te_rem_ra_ove_an_forspam at consistent.org
Fri Feb 1 02:47:36 CET 2008
On 2008-01-31, Bjoern Schliessmann <usenet-mail-0306.20.chr0n0ss at spamgourmet.com> wrote:
> Did you measure such impact on your application?
> Also see http://www.skymind.com/~ocrow/python_string/
I don't have a real application yet. That was, in fact, exactly the web
page which informed me that the MutableString class was not implemented
with mutable primitives.
> Look at "lower level" HLLs. In C++, you'd have to use
Well, in C++, I would use something like:
string has a default constructor, so I'll get a 5x5 array of empty
strings. Alternatively, I could use boost::array if I wanted container
If I needed something dynamically resizable, I could use:
vector<vector<string> > vs(5);
and then I could append elements to each one. If I wanted needed to
resize them all to 5 immediately, I would have to loop:
for (vector<vector<string> >::iterator i = vs.begin(); i != vs.end(); i++)
and that isn't particularly concise or elegant either, but the odds of
needing them to start out at size 5 and *also* be resizable later are
low for most applications.
> Personally, I like list comprehensions much better.
Perhaps the take-away lesson is that comprehensions should be seen as a
very fundamental operation in Python, and I have the wrong idea by
considering them advanced.
More information about the Python-list