def unique(list_):
    return len(set(list_)) == len(list_)

def get_combos(branches):
    by_parent = co.defaultdict(list)
for branch in branches:
    by_parent[branch.p].append(branch)
Combinatorics in Python