.def trans(paths): . tree = {} . for path in paths: . reduce(lambda branch,node: branch.setdefault(node,{}), path[:-2], tree)[path[-2]] = path[-1] . return tree Also seems to work. ;-) Jonathan.