看板 Python 關於我們 聯絡資訊
哈囉 我使用這兩行code, 執行後得到以下的NameError, 請問該如何解決? 先謝謝啦 s=map(lambda x : set(x), target.values()) print(reduce(lambda x,y: x.intersection(y), s)) NameError: global name 'reduce' is not defined ※ 引述《kadodo (想辦法突破)》之銘言: : target = {'a': [ab, cd, ef], 'b': [ac, cd, ef, gh], 'c': [bh, ef, cd, jk], ...} : 假設target還有很多keys... : 請問如何將 所有的 values of target取 set : 以我舉的例子 我想得到 一個 set (cd, ef) : 請教一下code該怎麼寫呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 192.203.57.28
AlanSung:更新你的 python? 看來是 2.4 版的? 02/20 17:38
AlanSung:oh, 3.0 ... 02/20 17:39
AlanSung:改成 functools.reduce 02/20 17:40
kadodo:Thanks, it works! 02/20 18:05
huggie:3.0怎麼變這麼麻煩 02/22 21:32