← Questions

Turn dotted keys into a nested dictionary

0
NetflixCodingLast asked Aug 2025

A model's weights come as a flat mapping from dotted names such as layer1.attention.query.weight to values. Convert it into a nested dictionary ({"layer1": {"attention": {"query": {"weight": ...}}}}). Handle numeric segments (list indices or keys), conflicts where a name is both a leaf and a prefix, and write the reverse conversion too.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding