Estadísticas del código: PowerSet Python - Python

sin imagen de perfil
Val: 2
Ha disminuido su posición en 20 puestos en Python (en relación al último mes)
Gráfica de Python

PowerSet Python


Python

Publicado el 19 de Abril del 2026 por Manuel Isaac (5 códigos)
453 visualizaciones desde el 19 de Abril del 2026
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Find the power set of each of these sets, where a and b are distinct elements.
# set {∅, {∅}}
 
from itertools import chain, combinations
 
 
# Define a function to generate the powerset of an iterable.
 
def powerset(iterable):
    s= list(iterable) # Convert the input iterable to a list.
    return list(chain.from_iterable(combinations(s, r) for r in range(len(s) + 1)))
 
l=[]
l.insert(0,[])
l.insert(1,[[]])
print(powerset(l))

144 visualizaciones durante los últimos 90 días


16
0