collections_extended is a pure Python module with no dependencies providing various extended collection types. It includes a bag (multiset) class, a setlist (ordered set / unique list) class, a bijection, a RangeMap, and an IndexedDict. It also offers frozen (hashable) variants of bags and setlists. The current version, 2.0.2, maintains an active development status with regular updates and is compatible with Python 3.7+.
pip install collections-extendedVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of `bag`, `setlist`, `IndexedDict`, and `RangeMap` from `collections-extended`.
Upgrade Python to 3.7+ or pin collections-extended to a 1.x version if Python 2.7/3.4/3.5 support is required.
Review code that uses `bag` multiplication (`*`) and adjust logic if the previous 'addition' behavior was expected. The new behavior is a cartesian product, yielding tuples.
If comparing `bag` instances with `set` instances, explicit conversion (e.g., `set(my_bag) == my_set`) or a different comparison logic may be necessary.
Update any direct imports or references to `_basebag` or `_basesetlist` to use `Bag` or `SetList`.
Check for element existence (e.g., `if element not in my_setlist: my_setlist.insert(...)`) or handle the `ValueError` if duplicate insertion is attempted.
If order-sensitive comparison is needed, convert `setlist` to a `list`. For set-based comparison, convert to a `set`.
Ensure the package is installed using pip: `pip install collections-extended` and that the import statement is `from collections_extended import ...`.
Ensure that elements added to `bag` or `frozenbag` are hashable. Use tuples instead of lists if the order matters, or convert mutable objects to their hashable equivalents before adding them.
Use the mutable versions (`bag` or `setlist`) if you need to add, remove, or modify elements after creation. If you need a modified version of a frozen collection, create a new one from the old one, e.g., `new_frozenbag = frozenbag(old_frozenbag | {'new_item'})`.Use the correct lowercase class name for import: `from collections_extended import bag`.