Is there a nicer way to do this?

Terry Reedy tjreedy at udel.edu
Fri Oct 5 06:31:21 CEST 2007


"Paul Hankin" <paul.hankin at gmail.com> wrote in message 
news:1191535908.219535.14890 at 57g2000hsv.googlegroups.com...
| On Oct 4, 10:53 pm, "Terry Reedy" <tjre... at udel.edu> wrote:
| > However,  mapping indexes to names should be more useful:
| >
| > >>> aNames = dict(enumerate(['foo', 'bar']))
| > >>> aNames
| >
| > {0: 'foo', 1: 'bar'}
|
| If you are right that a map from indices to name is best, there's no
| need for a dict: the original list already provides such a mapping.

Right.  The dict should be reversed, mapping names to indexes, if there 
were a use.






More information about the Python-list mailing list