June 2019
Beginner to intermediate
770 pages
19h 24m
English
We built a complete new collection. The ABC definitions included a number of methods automatically. These inherited methods might not be particularly efficient, but they're defined, they work, and we didn't write the code for them.
>>> s1 = Tree(["Item 1", "Another", "Middle"])
>>> list(s1)
['Another', 'Item 1', 'Middle']
>>> len(s1)
3
>>> s2 = Tree(["Another", "More", "Yet More"])
>>>
>>> union= s1 | s2
>>> list(union)
['Another', 'Another', 'Item 1', 'Middle', 'More', 'Yet More']
>>> len(union)
6
>>> union.remove('Another')
>>> list(union)
['Another', 'Item 1', 'Middle', 'More', 'Yet More']
This example shows us that the set union operator for set objects works properly, even though we didn't provide code ...
Read now
Unlock full access