listcrunch

1.0.1 · active · verified Thu Apr 16

listcrunch is a Python utility library (current version 1.0.1) that provides a simple, human-readable way to compress redundant sequential data within lists into a string format, and to decompress it back. It is a stable, focused library with no active new feature development since its last release in 2020.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `crunch` function to compress a list of sequential, redundant data into a human-readable string format, and then use the `uncrunch` function to restore the original list. The output format `VALUE:START-END;...` indicates that 'VALUE' appears from 'START' index to 'END' index (inclusive) in the original list.

from listcrunch import crunch, uncrunch

# Example data
data = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 1]

# Compress the data
compressed_string = crunch(data)
print(f"Original: {data}")
print(f"Compressed: {compressed_string}")
# Expected output: Original: [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 1]
# Expected output: Compressed: 1:0-8;2:9-10;3:11-13;1:14

# Uncompress the data
decompressed_list = uncrunch(compressed_string)
print(f"Decompressed: {decompressed_list}")
# Expected output: Decompressed: [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 1]

# Verify round trip
assert data == decompressed_list

view raw JSON →