Skip to content

Instantly share code, notes, and snippets.

@timothyekl
Created August 10, 2011 19:53
Show Gist options
  • Save timothyekl/1137985 to your computer and use it in GitHub Desktop.
Save timothyekl/1137985 to your computer and use it in GitHub Desktop.
Singleton tuplization of a set wrapper class's elements
class FooIterator:
def __init__(self, underlyingIter):
self.underlying = underlyingIter
def __iter__(self):
return self
def next(self):
try:
return (self.underlying.next(),)
except StopIteration:
raise
class Foo:
def __init__(self, data):
self.data = set(data)
def __iter__(self):
return self.data.__iter__()
def tuplize(self):
return FooIterator(self.__iter__())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment