, , . . node node .
, . python , dict . , , .
from collections import defaultdict
children = {
1: [2, 3, 4, 5, 6, 7, 8],
2: [3, 4, 5, 6, 7, 8, 9],
3: [9, 10],
4: [9, 10],
5: [9, 10],
6: [9, 10],
7: [9, 10],
8: [9, 10],
9: [10],
10: [11, 12, 13],
11: [14, 15],
12: [13, 14, 15],
13: [16, 17],
14: [16, 17],
15: [16, 17],
16: [18],
17: [18],
18: [19, 20],
19: [21, 22],
20: [21, 22],
21: [],
22: [],
}
parents = defaultdict(list)
for a, bs in children.iteritems():
for b in bs:
parents[b].append(a)
store = defaultdict(list)
for node in children.iterkeys():
store[(tuple(sorted(children[node])), tuple(sorted(parents[node])))].append(node)
for s in store.itervalues():
if len(s) > 1:
print s
, {11, 12} . 11 13.