Why I think range is a wart.

Bertrand Geston bergeston at yahoo.fr
Mon Mar 18 05:25:50 EST 2002


OK, I will try to take your point of view:
Following you, lists are a special kind of dictionnary where:
- keys are regular sequence of integers,
- keys are automatically managed :
    - automatically created when an element is put in the list,
    - modified for each element being over a removed or an inserted element.

I have to admit that I have some difficulties to think like that. I see a
list as being intrinsically different of a dictionnary because in a
dictionnary, the key (even if it is an integer) is something related to the
item. In a list, the index is the place of the item in the list. If you take
the item out of the list, the index doen't make sense at all anymore.

And if you need a dictionnary with integers keys, just build it:
makeDictFromList = lambda list: dict(zip(range(len(list)), list))

I admit that this doen't apply that much to tuples that can be more easily
seen as a special kind of dictionnaries if you really want it.

B.

PS Thanks to understand my bad english and to add some mathematical
formalism that I miss. I really appreciate.

"Magnus Lie Hetland" <mlh at vier.idi.ntnu.no> wrote in message
news:slrna954bc.h7j.mlh at vier.idi.ntnu.no...
> In article <a6qjeq$fvcf8$1 at ID-135695.news.dfncis.de>, Bertrand Geston
wrote:
> [...]
> >Let's keep things simple and understandable :
> >- lists are ordered sets,
> >- dictionnaries are "keyed" sets.
>
> The standard mathematical definition of sequences (as opposed to
> ordered sets) is a partial function mapping integers to elements. This
> seems awfully close to what you're calling "keyed" sets, by
> restricting the domain to integers. It also seems awfully close to
> Python lists (for instance). I see nothing inconsistent or illogical
> about list.keys. list.indices is an alternative, of course, but would
> not allow for polymorphic use.
>
> --
> Magnus Lie Hetland                                  The Anygui Project
> http://hetland.org                                  http://anygui.org





More information about the Python-list mailing list