Reference library

Big data & Spark

PySpark jobs, partitioning, batch processing, and large-dataset transform patterns.

1 match
Big data & Spark easy

How to Implement collect_list in Python

Group rows by a key and collect all corresponding values into a list — a pure-Python mock of Spark's collect_list aggregation.

collect_list aggregation grouping
Python
from collections import defaultdict

def collect_list(rows, key_field, value_field):
    grouped = defaultdict(list)
    for row in rows:
        grouped[row[key_field]].append(row[value_field])
    return dict(grouped)

if __name__ == "__main__":
    data = [
        {"dept": "sales", "emp": "alice"},
        {"dept"…
15 0 Open

Browse by section

Each section groups closely related Python snippets.

Big data & Spark — Python code examples

What you will find here

This page collects big data & spark snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.