I seem to recall reading somewhere that it is possible to concurrently
generate the index and value of a strings characters in a single for
statement. Is this true or did imagine it?
Here is the scenario:
Given an ASCII string of arbitrary length and content, generate
a sequence of
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),
its brain
JK Rowling
From: Adam [mailto:[EMAIL PROTECTED]
Sent: Friday, February 10, 2006 1:42 PM
To: Carroll, Barry
Cc: tutor@python.org
Subject: Re: [Tutor] Iterating over a string: index and value
Here's a list comprehension which does it:
print [(i
generate the index and value of a string's characters in a single for
statement. Is this true or did imagine it?
for i,c in enumerate('fred'): print i,c
...
0 f
1 r
2 e
3 d
Like that?
Alan G.
___
Tutor maillist - Tutor@python.org
On Fri, 2006-02-10 at 12:42 -0800, Carroll, Barry wrote:
I seem to recall reading somewhere that it is possible to concurrently
generate the index and value of a string’s characters in a single for
statement. Is this true or did imagine it?
Here is the scenario:
Given an ASCII