Naive idiom questions

Terran Melconian te_rem_ra_ove_an_forspam at consistent.org
Thu Jan 31 20:29:18 EST 2008


On 2008-02-01, Roger Miller <roger.miller at nova-sol.com> wrote:
> On Jan 31, 11:48 am, Grant Edwards <gra... at visi.com> wrote:
>> I'm not sure what you're asking.  AFAIK, the main reason that
>> strings are immutable is so they can be used as dict keys.
>
> I think its more fundamental than that.  If strings were mutable
> you would be constantly worrying about whether changing a string
> here might affect something there, or whether to write x = y or
> x = copy.copy(y).

Sure.  I don't think any of those considerations are fundamentally
different than what we face now with lists, though, are they?  Lists can
be thought of as the mutable version of the tuple, and sets come in a
pair with frozensets so you can get whichever flavor you need for your
application.  I'm all for the default string implementation being
immutable, since it facilitations certain operations and avoids certain
classes of problems, but it isn't obvious to me why there isn't a class
of a different name, such as "mutablestring", for when one wants that.
Even having just the += operator and slicing make modifications in place
could be a win.

I guess for complete symmetry, there should then be frozendicts as well,
although I don't envision a lot of use for them at the moment.



More information about the Python-list mailing list