Re: storing meta data on dictionary keys

2007-10-11 Thread Andreas Kraemer
On Oct 11, 1:42 pm, Erik Jones <[EMAIL PROTECTED]> wrote: > On Oct 11, 2007, at 2:25 PM, Andreas Kraemer wrote: > > > On Oct 11, 10:17 am, Erik Jones <[EMAIL PROTECTED]> wrote: > > >> No, duck typing and inheritance are two different things. Duck > >> typing is when you implement the same operatio

Re: storing meta data on dictionary keys

2007-10-11 Thread Erik Jones
On Oct 11, 2007, at 2:25 PM, Andreas Kraemer wrote: > On Oct 11, 10:17 am, Erik Jones <[EMAIL PROTECTED]> wrote: > >> No, duck typing and inheritance are two different things. Duck >> typing is when you implement the same operations as another object or >> class, whereas with inheritance you get

Re: storing meta data on dictionary keys

2007-10-11 Thread Andreas Kraemer
On Oct 11, 10:17 am, Erik Jones <[EMAIL PROTECTED]> wrote: > No, duck typing and inheritance are two different things. Duck > typing is when you implement the same operations as another object or > class, whereas with inheritance you get the same implementation as > that of the parent class. Exc

Re: storing meta data on dictionary keys

2007-10-11 Thread Erik Jones
On Oct 11, 2007, at 1:36 AM, Andreas Kraemer wrote: > On Oct 10, 9:00 pm, Erik Jones <[EMAIL PROTECTED]> wrote: >> If you're sure that 1. this use case won't grow and 2. that you'll >> only be the only person ever using code, then it's your choice of >> preference. Both of those points are equa

Re: storing meta data on dictionary keys

2007-10-11 Thread Andreas Kraemer
> > [...]In fact, now that I think of it, get_key > > is probably a bad name for it, get_other_object_with_this_same_key is > > probably more apt :) > > Or more precise: > get_key_that_was_used_when_value_was_inserted_into_dictionary :-) Or even more precisely: get_key_obj

Re: storing meta data on dictionary keys

2007-10-10 Thread Andreas Kraemer
On Oct 10, 9:00 pm, Erik Jones <[EMAIL PROTECTED]> wrote: > If you're sure that 1. this use case won't grow and 2. that you'll > only be the only person ever using code, then it's your choice of > preference. Both of those points are equally important. 1 is a > manageability issue in that you ar

Re: storing meta data on dictionary keys

2007-10-10 Thread Erik Jones
On Oct 10, 2007, at 6:40 PM, Andreas Kraemer wrote: > On Oct 9, 9:18 pm, Erik Jones <[EMAIL PROTECTED]> wrote: >> So, do you not keep references to your nodes anywhere but the actual >> graph dict? I kind of agree with Chris here in that two dicts will >> work. One for the nodes, indexed by thei

Re: storing meta data on dictionary keys

2007-10-10 Thread Andreas Kraemer
On Oct 9, 9:18 pm, Erik Jones <[EMAIL PROTECTED]> wrote: > So, do you not keep references to your nodes anywhere but the actual > graph dict? I kind of agree with Chris here in that two dicts will > work. One for the nodes, indexed by their strings. Yes, I guess that's exactly what I want. To kee

Re: storing meta data on dictionary keys

2007-10-09 Thread Erik Jones
On Oct 9, 2007, at 7:37 PM, Andreas Kraemer wrote: > From: Chris Mellon <[EMAIL PROTECTED]> > Sent: Tuesday, October 9, 2007 1:51:04 PM > > > Because, by definition, if you have the key then you don't need > to get > > it from the dict. What you're doing here is conflating 2 mappings > into >

Re: storing meta data on dictionary keys

2007-10-09 Thread Andreas Kraemer
From: Chris Mellon <[EMAIL PROTECTED]> Sent: Tuesday, October 9, 2007 1:51:04 PM > Because, by definition, if you have the key then you don't need to get > it from the dict. What you're doing here is conflating 2 mappings into > one: string value->person and person->values. Use 2 explicit dicts t

Re: storing meta data on dictionary keys

2007-10-09 Thread Chris Mellon
On 10/9/07, Andreas Kraemer <[EMAIL PROTECTED]> wrote: > > I sometimes find it useful to store meta data on dictionary keys, like in > the following example: > > class Dict(dict): > def __init__(self,*args,**kw): > self.key_dict = {} > super(Dict,self).__init__(*args,**kw) > def __setit

storing meta data on dictionary keys

2007-10-09 Thread Andreas Kraemer
I sometimes find it useful to store meta data on dictionary keys, like in the following example: class Dict(dict): def __init__(self,*args,**kw): self.key_dict = {} super(Dict,self).__init__(*args,**kw) def __setitem__(self,k,v): self.key_dict[k] = k super(Dict,self).__setitem