Mostrar los tags: Mathematics Discrets

Se ha encontrado 1 coincidencia
<<>>
Se ha buscado por el tag: Mathematics Discrets
sin imagen de perfil

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))