Adam, That is super! Just what I was looking for. Thanks!
And whaddya know? There it is in the Python 2.3 Library reference, section 2.1! Regards, Barry [EMAIL PROTECTED] 541-302-1107 ________________________ "Never trust anything that can think for itself if you can't see where it keeps its brain" JK Rowling >________________________________________ >From: Adam [mailto:[EMAIL PROTECTED] >Sent: Friday, February 10, 2006 1:42 PM >To: Carroll, Barry >Cc: [email protected] >Subject: Re: [Tutor] Iterating over a string: index and value > >Here's a list comprehension which does it: >>>> print [(i, ord(v)) for i, v in enumerate("abcdefg")] >[(0, 97), (1, 98), (2, 99), (3, 100), (4, 101), (5, 102), (6, 103)] > >and a for loop: > >>>> for i, v in enumerate("abcdefg"): >... tuplseq.append((i, ord(v))) >... >>>> tuplseq >[(0, 97), (1, 98), (2, 99), (3, 100), (4, 101), (5, 102), (6, 103)] > >how's that? _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
