所有子集的集合

编程入门 行业动态 更新时间:2024-10-09 10:20:02
本文介绍了所有子集的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 Python2 中我可以使用

In Python2 I could use

def subsets(mySet): return reduce(lambda z, x: z + [y + [x] for y in z], mySet, [[]])

查找mySet 的所有子集.Python 3 删除了 reduce.

to find all subsets of mySet. Python 3 has removed reduce.

对 Python3 进行同样简洁的重写是什么?

What would be an equally concise rewrite of this for Python3?

推荐答案

这是一个列表Python 中的幂集(所有子集的集合)算法.有些是递归的,有些是迭代的,有些不使用reduce.多种选择!

Here's a list of several possible implementations of the power set (the set of all subsets) algorithm in Python. Some are recursive, some are iterative, some of them don't use reduce. Plenty of options to choose from!

更多推荐

所有子集的集合

本文发布于:2023-11-29 15:50:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646850.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子集

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!