| 1 | initial version |
You don't have a set to begin with. CartesianProduct returns a special object. That object automatically converts to a list of lists when you pass it to Subsets. Then Subsets goes through that list of lists, and gets confused by the lists inside - it cannot make subsets out of them, because lists are not hashable. One way around is to use tuples instead of lists:
def Z(m,n):
return CartesianProduct(IntegerRange(m),IntegerRange(n))
print Subsets(map(tuple,Z(2,2)))
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.