esoteric question about dict keys (Re: age of Python programmers)

Steve lonetwin at gmail.com
Fri Aug 20 08:05:49 EDT 2004


Hi,
> Now the question. In "normal" dicts its not possible to use dictionaries
> (nor other kinds of mutable objects) as keys, if I undersand correctly
> this is a technical requirement. If I write my own dictionary-like
> object, on wich the mutability of the keys is not a technical issue, is
> considered blasphemous the use of dicts as keys? For example, querying
> an SQL table can be partially modelled as a dictionary access:
> 
> table[pkey_value] gives a record for this primary key
> 
> table[{'somefield':somevalue}] returns all the records where
> somefield=somevalue

...but the whole point of having keys is to uniquely identify a
record, so table[<whatever>] should always return *one* uniquely keyed
object.

Wouldn't something like 
     [ values for value in table['somefield'] if value == 'somevalue']
or
     table['somefield']['somevalue']
 be more a appropriate model ??

HTH
Steve


On Fri, 20 Aug 2004 12:19:01 +0200, Alexis Roda <alexis.roda at urv.es> wrote:
> This is my first message to the list, so I'll present myself and add my
> contribution to the "age of python programmes" thread.
> 
> My name is Alexis Roda, I'm 36 - 7/365 years old, I started programming
> with python two years ago, mainly because I started playing with zope.
> At first I was a reluctant Perl converted, although initially I hated
> python (well, I hated zope wich make me hate python) now I'm in love
> with both python and zope. I started programming at 15 with a Casio
> calculator (a kind of assembler), then an Amstrad CPC464 (Basic), a
> Macintosh Plus (Pascal, C, Lisp, assembler) and finally come to the
> PC/Linux world (assembler, C, C++, Perl, bash scripting, elisp and python).
> 
> Now the question. In "normal" dicts its not possible to use dictionaries
> (nor other kinds of mutable objects) as keys, if I undersand correctly
> this is a technical requirement. If I write my own dictionary-like
> object, on wich the mutability of the keys is not a technical issue, is
> considered blasphemous the use of dicts as keys? For example, querying
> an SQL table can be partially modelled as a dictionary access:
> 
> table[pkey_value] gives a record for this primary key
> 
> table[{'somefield':somevalue}] returns all the records where
> somefield=somevalue
> 
> or is preferable to define a query() method for these uses and restrict
> __getitem__ to mutable objects for the sake of consistency?
> 
> TIA
> --
>                                     ////
>                                    (@ @)
> ----------------------------oOO----(_)----OOo--------------------------
> <>               Ojo por ojo y el mundo acabara ciego
> /\ Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain)
> -----------------------------------------------------------------------
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list