Skip to content

Instantly share code, notes, and snippets.

@benjaminaaron
Created November 18, 2015 21:47
Show Gist options
  • Save benjaminaaron/c375b8a751f88bc77889 to your computer and use it in GitHub Desktop.
Save benjaminaaron/c375b8a751f88bc77889 to your computer and use it in GitHub Desktop.
subgroups and permutations in python
Set = ['A', 'B', 'C', 'D']
Subsets = []
n = len(Set)
for i in xrange(pow(2, n)):
binaryDigits = (bin(i)[2:]).zfill(n)
subset = ''
j = 0
for digit in binaryDigits:
if(digit == '1'):
subset += Set[j]
j += 1
Subsets.append(subset)
print 'distinct subgroups in set', Set, ':'
print Subsets
# - - - - - - - - - - - - - - - - -
import itertools
print 'permutations of set', Set, ':'
print list(itertools.permutations(Set))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment