From dc5710801266a7d4c07d7e853e4d3bb580bef3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 27 Mar 2019 15:34:11 +0100 Subject: [PATCH] Collection instead of Sequence --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a74a3fd..55f9239 100644 --- a/README.md +++ b/README.md @@ -887,11 +887,11 @@ class MyHashable: return hash(self.a) ``` -### Sequence +### Collection * **Methods do not depend on each other, so they can be skipped if not needed.** * **Any object with defined getitem() is considered iterable, even if it lacks iter().** ```python -class MySequence: +class MyCollection: def __init__(self, a): self.a = a def __len__(self): @@ -900,6 +900,8 @@ class MySequence: return self.a[i] def __setitem__(self, i, value): self.a[i] = value + def __contains__(self, value): + return value in self.a def __iter__(self): for el in self.a: yield el