def make_prefix_tree(flat_dict):
    """Convert a dictionary with keys of dotted strings into nested dicts with common prefixes.

    Ex: { 'abc.xyz': 1, 'abc.def': 2, 'www': 3} is converted to:
        { 'abc': {'xyz': 1, 'def': 2}, 'www': 3 }
    """
    tree = {}
    for key, value in flat_dict.items():
        subtree = tree
        parts = key.split('.')
        for part in parts[:-1]:
            if part not in subtree:
                subtree[part] = {}
            subtree = subtree[part]
        subtree[parts[-1]] = value

    return tree