Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2004-08-02 01:42:47
Size: 276
Editor: dsl254-010-130
Comment:
Revision 3 as of 2008-11-15 13:59:44
Size: 272
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
for (index, character) in enumerate( "hello" ):
  print "$%d: %s" % (index, character)
for index, character in enumerate("hello"):
  print "#%d: %s" % (index, character)

enumerate is easy to use:

   1 for index, character in enumerate("hello"):
   2   print "#%d: %s" % (index, character)

...which prints out:

#0: h
#1: e
#2: l
#3: l
#4: o

You can use it on just about any iterable sequence.

UsingEnumerate (last edited 2008-11-15 13:59:44 by localhost)

Unable to edit the page? See the FrontPage for instructions.