Re: [問題] 列出一個列表中所有子集合已刪文

看板Python作者 (阿寬)時間1年前 (2022/12/05 14:12), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/5 (看更多)
# 完全抄 itertools combinations的範例: https://pastebin.com/xzKiwfsX 可以適用任何iterable,等價於下面範例: In [1]: from itertools import chain, combinations ...: ...: ...: def powerset(iterable): ...: s = list(iterable) ...: return chain.from_iterable( ...: map(list, combinations(s, r)) ...: for r in range(len(s) + 1) ...: ) ...: ...: ...: list(powerset([1, 2, 3])) ...: Out[1]: [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]] -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 133.51.216.27 (日本) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1670220748.A.EF3.html
文章代碼(AID): #1ZZOlCxp (Python)
討論串 (同標題文章)
文章代碼(AID): #1ZZOlCxp (Python)