There is a given set S. I would like to search for elements from $S^n$ (the Cartesian product of $S$ with itself $n$ times) that verify certain properties. But I don't want to actually create $S^n$ because it takes up space.
For example to search for eligible elements in $S^3$, I could write
for x in S:
for y in S:
for z in S:
if P(x,y,z): print (x,y,z)
However $n$ not being fixed when I write the code, I cannot use the above method. Is there a way to do this elegantly? (I use Python if that's relevant) Thanks!
You could write a function to generate the members of the desired power set: