這應該是個 map reduce 的題目吧
l = [2, 3, 4, 5, 0, 1, 2, 3, 4, 2, 3, 5]
def func_map(a):
return [set([a]), set([a])]
def func_reduce(am, bm):
uaset, aset = am
ubset, bset = bm
unset = (uaset - bset) | (ubset - aset)
nset = aset | bset
return [unset, nset]
reduce(func_reduce, map(func_map, l))
先把值 map 成 uniq set, all number set
再 reduce 成 uniq set, all number set