Skip to content

Instantly share code, notes, and snippets.

@hectorip
Created August 18, 2013 08:57
Show Gist options
  • Select an option

  • Save hectorip/6260644 to your computer and use it in GitHub Desktop.

Select an option

Save hectorip/6260644 to your computer and use it in GitHub Desktop.
Algoritmo para obtener todos los subconjuntos de un conjunto
def getSubsets(conjunto):
subconjuntos=[]
set_size=len(conjunto)
if set_size>1:
subconjuntos+=getSubsets(conjunto[1:])
elemento=[conjunto[0]]
for sub in subconjuntos[:]:
subconjuntos.append(sub+elemento)
subconjuntos.append(elemento)
else:
subconjuntos+=[conjunto]
#print len(subconjuntos)
#subconjuntos.sort()
return subconjuntos
print getSubsets([i for i in range(20)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment