29  Networks

Each chapter here is short and dataset-driven, asking readers to apply Parts I–VI to one real phenomenon rather than introducing new machinery.

Chapter 27 — Networks: degree distributions in a scale-free network built from scratch via preferential attachment.

def preferential_attachment_step(degrees):
    total = sum(degrees.values())
    r = random.uniform(0, total)
    cumulative = 0
    for node, d in degrees.items():
        cumulative += d
        if cumulative >= r:
            return node