Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def oneBits(n):
- i = 0
- s = set()
- while n > 0:
- if n % 2 == 1:
- s.add(i)
- n = n / 2
- i += 1
- return s
- def powerSet(n):
- p = []
- for i in range(0, 2 ** n):
- p.append(oneBits(i))
- return p
- p = powerSet(3)
- # print all the elements
- for s in p:
- print s
- print ""
- print "few examples"
- print ""
- # print the intersection between the last set in P and the one before.
- print "intersection ", p[-1] , " with ", p[-2]
- print p[-1] & p[-2]
- # print the diff between
- print "diff ", p[-1] , "-", p[-2]
- print p[-1] - p[-2]
- # print the union
- print "union of", p[-1], " U ", p[-2]
- print p[-1] | p[-2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement