How to "dereference" an iterator?
Robert Dailey
rcdailey at gmail.com
Wed Oct 10 19:01:36 EDT 2007
Hi,
Suppose I wanted to manually iterate over a container, for example:
mylist = [1,2,3,4,5,6]
it = iter(mylist)
while True:
print it
it.next()
In the example above, the print doesn't print the VALUE that the iterator
currently represents, it prints the iterator itself. How can I get the value
'it' represents so I can either modify that value or print it? Thanks.
PS: Yes, I know that the While loop is messy and I should be prepared to
handle the StopIteration exception. However, if you guys can think of a
better alternative than the while loop I'd really appreciate it. Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071010/83642625/attachment.html>
More information about the Python-list
mailing list