for loop question

Robert Dailey rcdailey at gmail.com
Wed Oct 10 15:56:10 EDT 2007


Hi,

I'm currently writing my own CSV parser since the built in one doesn't
support Unicode. I'm wondering if there's a way to iterate over the
characters in a unicode string and have access to both the 'current' and the
'next' characters each iteration. For example:

test = u"Hello World"

for cur,next in test:
    print cur,next

Ideally, this would output:

'H', 'e'
'e', 'l'
'l', 'l'
'l', 'o'
etc...

Of course, the for loop above isn't valid at all. I am just giving an
example of what I'm trying to accomplish. Anyone know how I can achieve the
goal in the example above? Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071010/7b6af767/attachment.html>


More information about the Python-list mailing list