A memory-efficient Python sequence wrapper that applies slicing operations lazily, deferring data access until elements are actually needed.
Project description
lazily-sliced
A memory-efficient Python sequence wrapper that applies slicing operations lazily, deferring data access until elements are actually needed.
Features
- Zero-copy slicing: Avoids immediate data duplication when slicing sequences
- Full Sequence interface: Implements all
collections.abc.Sequenceoperations - Portable: Python 2 & 3 compatible, no dependencies
- Memory efficient: Uses
__slots__and lazy evaluation - Composable: Handles nested slicing operations efficiently
Installation
pip install lazily-sliced
Usage
from lazily_sliced import LazilySliced
# Create from any sequence
data = list(range(1000))
lazy = LazilySliced(data, slice(100, 200))
# Standard sequence operations work
print(len(lazy)) # 100
print(lazy[10]) # 110
print(105 in lazy) # True
# Supports nested slicing
subset = lazy[10:20:2]
print(subset) # LazilySliced([110, 112, 114, 116, 118])
for item in lazy:
print(item)
When to Use
Ideal for:
- Working with large sequences where you need small slices
- Memory-constrained environments
- Chaining multiple slicing operations
- Cases where immediate data copying is expensive
Performance Characteristics
| Operation | Time Complexity | Notes |
|---|---|---|
len() |
O(1) | |
| Index access | O(1) | |
| Iteration | O(n) | Proportional to slice size |
in check |
O(n) | Worst case scans entire slice |
| Memory usage | O(1) | Constant overhead |
Limitations
- Read-only (doesn't support item assignment)
- Underlying sequence must support integer indexing
- Slices must be within bounds of original sequence
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lazily_sliced-0.1.0a0.tar.gz.
File metadata
- Download URL: lazily_sliced-0.1.0a0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbb86ce6a1c42c2d444bcce427a175eba4d586d5def83d6fc3cd4c6a28e5cfb7
|
|
| MD5 |
f88fd1ef31500a9333e560ab5699f17f
|
|
| BLAKE2b-256 |
099cff6554fe0794093067315ce342b87c68418d13e67bd3be036707bad576da
|
File details
Details for the file lazily_sliced-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: lazily_sliced-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ab4fcd6b4a87d38c904f126c4ed454281f78eba345c7242b051a9c41c33d314
|
|
| MD5 |
5456e21b2e4dc976293c9f81f917a1d2
|
|
| BLAKE2b-256 |
25d99a3eae40fd40be56dc8414db3ff6c34897512d6e75200c8e26717d8a53b2
|