Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
7-liner: Sim0000's simplified solution in Clear category for What Is Wrong With This Family? by przemyslaw.daniel
def is_family(data):
ancestor = {x: set() for x in sum(data, [])}
for parent, child in data:
if (ancestor[parent] | {parent}) & (ancestor[child] | {child}):
return False
ancestor[child] |= ancestor[parent] | {parent}
return list(ancestor.values()).count(set()) == 1
Sept. 2, 2017
Comments: