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 for it specifically. As this is a bag, items are duplicated properly, too.