for loop question

Rafael Sachetto rsachetto at gmail.com
Wed Oct 10 16:03:40 EDT 2007


Try this:

test = u"Hello World"

n = range(len(test))

for i in n:
   cur  =  test[i]
   try:
      next = test[i+1]
   except:
      next = ""
    print cur, next

just

On 10/10/07, Robert Dailey <rcdailey at gmail.com> wrote:
>
> 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.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Rafael Sachetto Oliveira

Sir - Simple Image Resizer
http://rsachetto.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071010/b5585fc4/attachment.html>


More information about the Python-list mailing list