Problems with string and lists (searching and replaceing)

Alex Martelli aleax at aleax.it
Mon Sep 22 10:30:08 EDT 2003


jblazi wrote:

> On Mon, 22 Sep 2003 12:49:24 +0000, Alex Martelli wrote:
> 
>> Basically, the change from "x[y]=z" to "x=x[:y]+z+x[y+1:]" is just
>> not "traumatic" enough, in my opinion, to warrant considering this
>> a seriously complicated problem ("not seem simple at all").
> 
> Of course, you are right. The possibility to create a new string dawned
> upon me later when I was already lying in my bed...
> Of course, in this case a lot of activity takes place in the background
> (memory objects have to be allocated and deallocated) and if efficiency
> played a rôle... In this case it does not and your solution is the right
> one.

Yes, you did indicate it was an exercise, so efficiency clearly could
not matter at this micro-level.  If it did I might suggest array.array
or the like.


> In C strings are mutable and so you can work in situ but usually those
> zero terminated strings have their disadvantages as well...

Sure, they're lots of trouble (non-expandable, can't contain arbitrary
bytes, etc).


> Thank you for your help.

You're welcome!


Alex





More information about the Python-list mailing list