|
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 string of arbitrary length and content, generate
a sequence of tuples whose elements are: the index of each character in the string,
and data based on the ordinal value of the
character in the ASCII collating sequence. The brute force way to do this is >>>>>>>>>> tuplseq = () for idx in mystr: char = mystr[idx] ordval = ord(char) data = ""> tuplseq.append(idx, data) >>>>>>>>>> Is there a way to generate the character (or its ord value)
along with the index? E.g.: >>>>>>>>>> tuplseq = () for idx ordval in XXXXXXXXX: tuplseq.append(idx, process(ordval)) >>>>>>>>>> Where XXXXXXXXX is some construct using mystr. BTW, this is for internal software for our test group.
Thanks in advance for your help. Barry 541-302-1107 ________________________ "Never trust anything that can think for itself if you can't see where it keeps its brain" JK Rowling |
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
