On 8/7/07, Greg Ewing <[EMAIL PROTECTED]> wrote:
> My instinct with regard to sets is the other way around,
> i.e. use immutable sets unless there's a reason they
> need to be mutable. The reason is safety -- accidentally
> trying to mutate an immutable object fails more quickly
> and obviously than the converse.
But this is impractical -- a very common way to work is to build up a
set incrementally. With immutable sets this would quickly become
O(N**2). That's why set() is mutable and {...} creates a set, and the
only way to create an immutable set is to use frozenset(...).
> If Python had had both mutable and immutable strings
> from the beginning, would you be giving the same
> advice, i.e. use mutable strings unless they need to
> be immutable? If not, what makes strings different from
> sets in this regard?
That's easy. sets are mutable for the same reason lists are mutable --
lists are conceptually containers for "larger" amounts of data than
strings. I don't adhere to the "let's just make copying really fast
by using tricks like refcounting etc." school -- that was a pain in
the B* for ABC.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com