[Python-Dev] re: PEP 279 revisited, formally

Magnus Lie Hetland magnus@hetland.org
Sat, 27 Apr 2002 21:02:40 +0200


Tim Peters <tim.one@comcast.net>:
>
> [Guido]
> > ...
> > So enumerate() it is.  (Specifically not enum() because of the C/C++
> > meaning of that word.)
> 
> The C/C++ meaning isn't a barrier to me:  a C enum decl without embedded '='
> must associate 0 with the first name, 1 with the second name, and so on.
> Indeed, if the Python enum returned pairs in (value, index) order,
> 
>     dict(enum(['apple', 'pear', 'godzilla'])
> 
> would create the dict
> 
>     {'apple': 0, 'pear': 1, 'godzilla': 2}
> 
> which is about as close to the C
> 
>     enum {apple, pear, godzilla};
>     /* now apple==0, pear==1, godzilla==2 */
> 
> as you can get with a Python function.

+1

--
Magnus Lie Hetland                                  The Anygui Project
http://hetland.org                                  http://anygui.org