作者retard (Baby baby~~)
看板Python
标题Re: [问题]不用for回圈寻找阵列中只出现过一次的资料
时间Mon May 12 04:57:28 2014
这应该是个 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
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 218.161.71.110
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Python/M.1399841851.A.25C.html
1F:推 apua:出现啦!!! 05/12 11:29
2F:→ apua:``set([a])`` 可以写成 ``{a}`` 05/12 11:50
3F:→ apua:``return [unset, nset]`` 可以写成 ``return unset, nset`` 05/12 11:50
4F:→ apua:会更精简些 05/12 11:50