Skip to content

Instantly share code, notes, and snippets.

@fumieval
Created July 5, 2012 07:54
Show Gist options
  • Save fumieval/3052153 to your computer and use it in GitHub Desktop.
Save fumieval/3052153 to your computer and use it in GitHub Desktop.
何回でも列挙できるイテレータを作るクラス
class MemoizedIterator:
def __init__(self, iterable):
self.iterator = iterable
self.elements = []
def __iter__(self):
for i in self.elements:
yield i
for i in self.iterator:
self.elements.append(i)
yield i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment