Re: [問題] 如何將dict的values取set
再請問一下
我想用一個變數來接
var_a = reduce(lambda x,y: x.intersection(y), s)
TypeError: reduce() of empty sequence with no initial value.
請問該如何解決?
我用Help去看 還是看不懂
reduce(function, sequence[, initial]) -> value
Apply a function of two arguments cumulatively to the items of a sequence,
from left to right, so as to reduce the sequence to a single value.
※ 引述《kadodo (想辦法突破)》之銘言:
: 哈囉 我使用這兩行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
推
02/20 18:28, , 1F
02/20 18:28, 1F
→
02/20 18:29, , 2F
02/20 18:29, 2F
討論串 (同標題文章)
Python 近期熱門文章
PTT數位生活區 即時熱門文章