<detailsopen><summary><strong>What exactly is <code><collection></code>?</strong></summary><br>
<detailsopen><summary><strong>What exactly is <code><collection></code>?</strong></summary><br>
Collection is my name for an iterable object. An iterable object in Python is any object that has at least one of iter() and getitem() special methods defined. By convention, <code><object>.__iter__()</code> should return an iterator of object's items and <code><object>.__getitem__(<index>)</code> an item at that index. I chose not to use the name iterable because it sounds scarier and more vague than collection, even though it has a precise definition.<br><br>
Collection is my name for an iterable object. An iterable object in Python is any object that has at least one of iter() and getitem() special methods defined. By convention, <code><object>.__iter__()</code> should return an iterator of object's items and <code><object>.__getitem__(<index>)</code> an item at that index. I chose not to use the name iterable because it sounds scarier and more vague than collection, even though it has a precise definition.<br><br>
To make matters a bit more confusing, an abstract base class called Iterable doesn't fully follow this definition. An expression <code>instanceof(<object>, collections.abc.Iterable)</code> only checks whether an object has iter() special method, disregarding the getitem().<br><br>
Although collection has no definition in Python's <ahref="https://docs.python.org/3/glossary.html">glossary</a>, there exists a Collection abstract base class. Expression <code>instanceof(<object>, collections.abc.Collection)</code> returns 'True' for any object that has len() and at least one of iter() and getitem() special methods defined. By convention, <code><object>.__len__()</code> should return the number of object's elements.
To make matters a bit more confusing, an abstract base class called Iterable doesn't fully follow this definition. An expression <code>isinstance(<object>, collections.abc.Iterable)</code> only checks whether an object has iter() special method, disregarding the getitem().<br><br>
Although collection has no definition in Python's <ahref="https://docs.python.org/3/glossary.html">glossary</a>, there exists a Collection abstract base class. Expression <code>isinstance(<object>, collections.abc.Collection)</code> returns 'True' for any object that has len() and at least one of iter() and getitem() special methods defined. By convention, <code><object>.__len__()</code> should return the number of object's elements.
</details><br>
</details><br>
<detailsopen><summary><strong>What about PEP 8?</strong></summary><br>
<detailsopen><summary><strong>What about PEP 8?</strong></summary><br>