Python Forum
iterating an interator partially then resuming
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iterating an interator partially then resuming
#2
Iterators are objects, just like everything else:

>>> x = list(range(10))
>>> it = iter(x)
>>> for a in it:
...     print(a)
...     if a == 4:
...         break
...
0
1
2
3
4
>>> for b in it:
...     print(b)
...
5
6
7
8
9
However, I don't believe you can make iterators go backwards. You could recreate the iterator. You could also make a wrapper class for an iterator that keeps track of what was already iterated over in a stack, and then call it back somehow.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: iterating an interator partially then resuming - by ichabod801 - Apr-30-2019, 02:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [3.4.4] Last loop element partially done nolme 5 3,158 May-08-2018, 03:25 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020