Browse Source

Iterable duck types

pull/52/head
Jure Šorn 5 years ago
parent
commit
0c8bdc682a
2 changed files with 6 additions and 4 deletions
  1. 5
      README.md
  2. 5
      index.html

5
README.md

@ -1205,8 +1205,9 @@ class MyIterable:
def __init__(self, a):
self.a = a
def __iter__(self):
for el in self.a:
yield el
return iter(self.a)
def __contains__(self, el):
return el in self.a
```
```python

5
index.html

@ -1144,8 +1144,9 @@ Hello World!
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, a)</span>:</span>
self.a = a
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__iter__</span><span class="hljs-params">(self)</span>:</span>
<span class="hljs-keyword">for</span> el <span class="hljs-keyword">in</span> self.a:
<span class="hljs-keyword">yield</span> el
<span class="hljs-keyword">return</span> iter(self.a)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__contains__</span><span class="hljs-params">(self, el)</span>:</span>
<span class="hljs-keyword">return</span> el <span class="hljs-keyword">in</span> self.a
</code></pre></div></div>

Loading…
Cancel
Save