|
@ -887,11 +887,11 @@ class MyHashable: |
|
|
return hash(self.a) |
|
|
return hash(self.a) |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
### Sequence |
|
|
|
|
|
|
|
|
### Collection |
|
|
* **Methods do not depend on each other, so they can be skipped if not needed.** |
|
|
* **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().** |
|
|
* **Any object with defined getitem() is considered iterable, even if it lacks iter().** |
|
|
```python |
|
|
```python |
|
|
class MySequence: |
|
|
|
|
|
|
|
|
class MyCollection: |
|
|
def __init__(self, a): |
|
|
def __init__(self, a): |
|
|
self.a = a |
|
|
self.a = a |
|
|
def __len__(self): |
|
|
def __len__(self): |
|
@ -900,6 +900,8 @@ class MySequence: |
|
|
return self.a[i] |
|
|
return self.a[i] |
|
|
def __setitem__(self, i, value): |
|
|
def __setitem__(self, i, value): |
|
|
self.a[i] = value |
|
|
self.a[i] = value |
|
|
|
|
|
def __contains__(self, value): |
|
|
|
|
|
return value in self.a |
|
|
def __iter__(self): |
|
|
def __iter__(self): |
|
|
for el in self.a: |
|
|
for el in self.a: |
|
|
yield el |
|
|
yield el |
|
|