Iteration Utilities

0.13.0 · active · verified Wed Apr 15

iteration_utilities is a general-purpose collection of tools for functional programming based on Python's iterators and generators. It provides a wide array of functions, many inspired by the `itertools` module's recipes and the `toolz` package. Large fractions of its code are implemented in C for optimized performance. The library is under ongoing development, with the current stable version being 0.13.0, and its API may change in future releases.

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of the `Iterable` class for chaining methods and direct imports of utility functions like `duplicates` and `all_distinct`.

from iteration_utilities import Iterable, duplicates, all_distinct

# Example 1: Chaining operations with Iterable
data = [1, 2, 2, 3, 4, 4, 5, 5, 5]
processed_data = Iterable(data).filter(lambda x: x % 2 == 0).unique_everseen().as_list()
print(f"Processed even unique data: {processed_data}")

# Example 2: Using a standalone function like duplicates
duplicate_items = list(duplicates(data))
print(f"Duplicate items: {duplicate_items}")

# Example 3: Using all_distinct
is_all_distinct = all_distinct([1, 2, 3, 4])
is_not_distinct = all_distinct([1, 2, 2, 3])
print(f"[1, 2, 3, 4] all distinct? {is_all_distinct}")
print(f"[1, 2, 2, 3] all distinct? {is_not_distinct}")

view raw JSON →