Hi,<br><br>I suppose my question in general is goofy to native python programmers. I'm originally a C++ programmer and I have a hard time not relating iterators in python to iterators in STL lol. What I was actually trying to accomplish was to iterate over 2 iterators using 1 for loop, however I found that the zip() function allows me to do this quite easily:
<br><br>list1 = [1,2,3]<br>list2 = [4,5,6]<br><br>for i1,i2 in zip( list1, list2 ):<br>    # do something here...<br><br>In one of my earlier threads in this group someone had ended up using zip(). After reviewing that thread again I found that I could also use it to solve this problem as well. Sorry for lack of details. Thanks for everyone's help.
<br><br><div><span class="gmail_quote">On 10/10/07, <b class="gmail_sendername">Steven D'Aprano</b> <<a href="mailto:steve@remove-this-cybersource.com.au">steve@remove-this-cybersource.com.au</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The original post seems to have been eaten, so I'm replying via a reply.<br>Sorry for breaking threading.<br><br>> On Wed, 2007-10-10 at 18:01 -0500, Robert Dailey wrote:<br>>> Hi,<br>>><br>>> Suppose I wanted to manually iterate over a container, for example:
<br>>><br>>> mylist = [1,2,3,4,5,6]<br>>><br>>> it = iter(mylist)<br>>> while True:<br>>>     print it<br>>>     it.next()<br>>><br>>> In the example above, the print doesn't print the VALUE that the
<br>>> iterator currently represents, it prints the iterator itself. How can I<br>>> get the value 'it' represents so I can either modify that value or<br>>> print it? Thanks.<br><br>it = iter(mylist)
<br>while True:<br>    print it.next()<br><br>but that will eventually end with an exception. Better to let Python<br>handle that for you:<br><br>it = iter(mylist)<br>for current in it:<br>    print current<br><br>Actually, since mylist is already iterable, you could just do this:
<br><br>for current in mylist:<br>    print current<br><br>but you probably know that already.<br><br><br>--<br>Steven.<br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list
</a><br></blockquote></div><br>