Getting the subsets of a set in Python

前端 未结 7 2010
清歌不尽
清歌不尽 2020-12-03 23:19

Suppose we need to write a function that gives the list of all the subsets of a set. The function and the doctest is given below. And we need to complete the whole definitio

相关标签:
7条回答
  • 2020-12-03 23:58
    >>> s=set(range(10))
    >>> L=list(s)
    >>> subs = [{L[j] for j in range(len(L)) if 1<<j&i} for i in range(1,1<<len(L))]
    >>> s in subs
    True
    >>> set() in subs
    False
    
    0 讨论(0)
提交回复
热议问题