bearophileHUGS at bearophileHUGS at
Fri Jan 13 06:10:35 EST 2006

Raymond Hettinger:

>I'm curious whether you've had an actual use for dictionaries as keys.<

I've never had this need (probably because it's an unsupported thing to
do too).

>Likewise, how about frozensets?  Have you had occasion to use them as keys?  They were created to support sets of sets, yet even that doesn't come-up often.<

I use sets all the time. And doing a little of mathematics it's rather
common to need subsets too, I have had this "need" 3-4 times. But the
implementation of subsets is "broken" (= no dynamic subsets allowed)
and frozen subsets aren't much useful.

>So why build a mechanism to automate a process that no one uses?<

You are right, frozedicts aren't much useful.
Maybe that freezing protocol was useful for user defined objects too.

>Also note that Guido has said over and over that tuples are NOT frozenlists. Even with a mechanism to freeze lists, tuples won't go away.<

Lists and fronzensets look like a duplication to me, so the freezing
operation was meant to remove them too.

>The term "freezing" inaccurately suggests an in-place operation; however, the PythonWay(tm) is to create new objects (i.e. given a mutable set s, the result of frozenset(s) is a new container).<

It seems sometimes Py doesn't follow its own PythonWay(tm)  :-)
But I agree that sometims consistency can be useful.

Thank you for your (good as usual) comments, Raymond.
(Strong rigour is necessary near the last stages, before the actual
implementation of an idea, but in most cases the creation of ideas
works better in a tolerant and more relaxed environment.)


Mike Meyer:

>Freezing in place is problematical. For this to work as intended, all the values in the container have to be frozen as well.<

Right, I was talking about deep (recursive) freezing in the original
post too.

>Actually, I like the "len" model, which would be a new builtin that uses the __freeze__ method.<

Well, I presume this is a matter of personal tastes and consistency
too. This time I appreciate the freeze() too, but probably some people
can think that adding .len, .copy(), .del(), .freeze() methods to most
objects is more regular:

len(l)           l.len
copy.copy(l)     l.copy()
|l|   freeze(l)  l.freeze()
del l            l.del()


More information about the Python-list mailing list