Re: Dictionary keys (again) (was Re: lambda)

2005-01-20 Thread Nick Coghlan
Antoon Pardon wrote: As you said yourself, people use shortcuts when they express themselves. With 'mutable key' I mean a mutable object that is used as a key. That doesn't contradict that the key itself can't change because it is inaccessible. Yeah - this was the point of terminology that was gett

Re: Dictionary keys (again) (was Re: lambda)

2005-01-20 Thread Nick Coghlan
David Eppstein wrote: Yes, and what should the following do? lst1 = [1] lst2 = [2] dct = {lst1: "1", lst2: "2"} lst2[0]=1 lst1[0]=2 print dct[[1]] print dct[[2]] Provide yet another example for why mutable keys are almost guaranteed to result in suprising semantics :) Cheers, Nick. -- Nick Coghla

Re: Dictionary keys (again) (was Re: lambda)

2005-01-19 Thread David Eppstein
In article <[EMAIL PROTECTED]>, Nick Coghlan <[EMAIL PROTECTED]> wrote: > For a 'mutable key' to make sense, the following: > > lst = [] > dct = {l: "Hi!"} > print dct[[]] > print dct[lst] > lst.append(1) > print dct[[1]] > print dct[lst] > > Should print: > Hi > Hi > Hi > Hi Yes, and what sho

Re: Dictionary keys (again) (was Re: lambda)

2005-01-19 Thread Steven Bethard
Nick Coghlan wrote: For a 'mutable key' to make sense, the following: lst = [] dct = {l: "Hi!"} print dct[[]] print dct[lst] lst.append(1) print dct[[1]] print dct[lst] Should print: Hi Hi Hi Hi And here's an implementation that does so: py> class sillydict(dict): ... def __getitem__(self, key)

Re: Dictionary keys (again) (was Re: lambda)

2005-01-19 Thread Steven Bethard
David Eppstein wrote: In article <[EMAIL PROTECTED]>, Nick Coghlan <[EMAIL PROTECTED]> wrote: For a 'mutable key' to make sense, the following: lst = [] dct = {l: "Hi!"} print dct[[]] print dct[lst] lst.append(1) print dct[[1]] print dct[lst] Should print: Hi Hi Hi Hi Yes, and what should the fo

Re: Dictionary keys (again) (was Re: lambda)

2005-01-19 Thread Antoon Pardon
Op 2005-01-19, Nick Coghlan schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> A rule of thumb is context sensitive. If circumstances change, >> so do the rules of thumb. Principles have a broader field >> of application. >> >> IMO there is nothing principally wrong with using a mutable object

Re: Dictionary keys (again) (was Re: lambda)

2005-01-19 Thread Just
In article <[EMAIL PROTECTED]>, Nick Coghlan <[EMAIL PROTECTED]> wrote: > Antoon Pardon wrote: > > A rule of thumb is context sensitive. If circumstances change, > > so do the rules of thumb. Principles have a broader field > > of application. > > > > IMO there is nothing principally wrong with