Zope Sequence Sort
raw JSON → 6.0 verified Mon Apr 27 auth: no python
Provides support for sorting sequences by one or more criteria, including ascending/descending order and case-insensitive comparisons. Current version: 6.0 (requires Python >=3.9). Maintained as part of the Zope Foundation, releases are stable but infrequent.
pip install zope-sequencesort Common errors
error ModuleNotFoundError: No module named 'zope.sequencesort' ↓
cause Package not installed or wrong import path.
fix
Install with 'pip install zope-sequencesort' and import as 'from zope.sequencesort import sort'.
error TypeError: sort() argument 2 must be tuple, not tuple ↓
cause Passing a single sort key tuple instead of a tuple containing that tuple.
fix
Wrap the key tuple in an extra set of parentheses: sort(items, (('name', False, False),))
error AttributeError: 'dict' object has no attribute 'name' ↓
cause Sort key uses getattr, but items are dictionaries; attribute access fails.
fix
Convert dicts to objects (e.g., using types.SimpleNamespace) or sort using Python's sorted() with a lambda.
Warnings
gotcha The sort function expects a sequence and a tuple of sort keys. Each sort key is a tuple of (attr, reverse, case_insensitive). The default for both reverse and case_insensitive is False, but you must pass a tuple for each key. ↓
fix Ensure you pass a tuple of tuples, e.g., (('name', False, False),). Do not pass a single tuple without the outer parentheses.
gotcha The sort key's first element is an attribute name (string) used for getattr. It does not work for nested attributes or item access like 'key.subkey'. ↓
fix Pre-process your data to flatten nested structures before sorting, or use a lambda with Python's sorted().
gotcha The package is very old and may not be compatible with Python 3.10+ if using deprecated 'distutils'. However, version 6.0 requires Python >=3.9 and should work. ↓
fix If you encounter install errors, upgrade pip and setuptools, or use a virtual environment.
Imports
- sort
from zope.sequencesort import sort
Quickstart
from zope.sequencesort import sort
# Simple list of dictionaries
items = [{'name': 'Charlie'}, {'name': 'Alice'}, {'name': 'Bob'}]
# Sort by 'name' ascending, case-insensitive
sorted_items = sort(items, (('name', False, False),))
print([item['name'] for item in sorted_items])
# Output: ['Alice', 'Bob', 'Charlie']