Is there a nicer way to do this?

Paul Hankin paul.hankin at
Fri Oct 5 00:11:48 CEST 2007

On Oct 4, 10:53 pm, "Terry Reedy" <tjre... at> 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.

Paul Hankin

More information about the Python-list mailing list