[Python-Dev] Re: PEP 279 (original) (raw)

Raymond Hettinger python@rcn.com
Sat, 30 Mar 2002 09:07:16 -0500


[RDH]

> Executive Summary: > 1. iterindexed(collection) --> accepted [GvR] Except I want to think more about the name.

Okay, here's what we have so far:

iterindexed()-- five syllables is a mouthfull index() -- nice verb but could be confused the .index() method indexed() -- widely liked however adjectives should be avoided count() -- direct and explicit but often used in other contexts itercount() -- direct, explicit and hated by more than one person enumerate() -- a contender but doesn't mention iteration or indices iteritems() -- already used by dictionaries for key:value pairs

Raymond Hettinger, CPA


def iterindexed(collection): 'Generates an indexed series: (0,coll[0]), (1,coll[1]) ...'
i = 0 it = iter(collection) while 1: yield (i, it.next()) i += 1