Re: Naive idiom questions
- From: Bjoern Schliessmann <usenet-mail-0306.20.chr0n0ss@xxxxxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 23:09:55 +0100
Terran Melconian wrote:
* Why are there no real mutable strings available?
I found MutableString in UserString, but further research
indicates that it is horribly inefficient and actually just
wraps immutable strings for the implementation.
Did you measure such impact on your application?
Also see http://www.skymind.com/~ocrow/python_string/
I want to be able to accumulate a string with +=, not by going
through an intermediate list and then doing ''.join(), because
I think the latter is ugly.
'hameggs'yummy = "ham"
yummy += "eggs"
yummy
There are also times when I'd like to use the string as a
modifiable buffer.
Use a list instead. When done with modifications you may concatenate
its contents to a string using "".join(my_list).
* What's the best way to initialize a list of lists?
[...]
l=[[None]*5 for i in range(5)]
I don't particularly like it, though. It bothers me to have
to explain list comprehensions, which are a moderately
advanced feature conceptually, just to initialize an array.
Look at "lower level" HLLs. In C++, you'd have to use
int my_array[5][5];
for (int i=0; i<5; ++i)
for (int j=0; j<5; j++)
my_array[i][j] = -1;
Personally, I like list comprehensions much better.
Regards,
Björn
--
BOFH excuse #254:
Interference from lunar radiation
.
- References:
- Naive idiom questions
- From: Terran Melconian
- Naive idiom questions
- Prev by Date: Re: char string 2 hex string
- Next by Date: Re: pyExcelerator - Can I read and modify an existing Excel-WorkBook?
- Previous by thread: Re: Naive idiom questions
- Next by thread: Re: Naive idiom questions
- Index(es):