diff options
author | Raymond Hettinger <python@rcn.com> | 2008-02-08 23:46:23 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-02-08 23:46:23 (GMT) |
commit | c1b6a4a1fd4de335426ffa3a8df2300aefed7a80 (patch) | |
tree | a9768f3c1c69b5cbd471e669164f3f57db42dfcd /Doc | |
parent | 8eed44922a2516a0463071f35dc15494165e00a1 (diff) | |
download | cpython-c1b6a4a1fd4de335426ffa3a8df2300aefed7a80.zip cpython-c1b6a4a1fd4de335426ffa3a8df2300aefed7a80.tar.gz cpython-c1b6a4a1fd4de335426ffa3a8df2300aefed7a80.tar.bz2 |
Smalls improvement to example in the docs for collections ABCs.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/collections.rst | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 8e04475..f465c77 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -43,10 +43,8 @@ ABC Notes :class:`Iterable`, and :class:`Sized`, and in addition defines ``__getitem__()``, ``get()``, - ``__contains__()``, ``__len__()``, ``__eq__()``, ``__ne__()``, - ``__iter__()``, ``keys()``, - ``items()``, and ``values()`` + ``keys()``, ``items()``, and ``values()`` :class:`collections.MutableMapping` Derived from :class:`Mapping` :class:`collections.Sequence` Derived from :class:`Container`, :class:`Iterable`, and :class:`Sized`, @@ -83,9 +81,13 @@ The ABC supplies the remaining methods such as :meth:`__and__` and :meth:`isdisjoint` :: class ListBasedSet(collections.Set): - 'Alternate set implementation favoring space over speed' + ''' Alternate set implementation favoring space over speed + and not requiring the set elements to be hashable. ''' def __init__(self, iterable): - self.elements = list(set(iterable)) + self.elements = lst = [] + for value in iterable: + if value not in lst: + lst.append(value) def __iter__(self): return iter(self.elements) def __contains__(self, value): |