Skip to content

Instantly share code, notes, and snippets.

@ktl014
Created February 26, 2018 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktl014/5c8d53faab18740ad8d6ccd1e55f9cc3 to your computer and use it in GitHub Desktop.
Save ktl014/5c8d53faab18740ad8d6ccd1e55f9cc3 to your computer and use it in GitHub Desktop.
>>> class Library(object):
... def __init__(self):
... self.books = { 'title' : object, 'title2' : object, 'title3' : object, }
... def __getitem__(self, i):
... return self.books[i]
... def __iter__(self):
... return self.books.itervalues()
...
>>> library = Library()
>>> library['title']
<type 'object'>
>>> for book in library:
... print book
...
<type 'object'>
<type 'object'>
<type 'object'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment