Could anybody please help me understand the below statement in the code below it?
cartesian_powers = [ i+(a,) for i in cartesian_powers for a in A]
Specifically the role of i+(a,)
?
Please explain the answer as much as possible.
Code:
A = {1, 2, 3}
k = 2
# Initialize every element as a tuple
cartesian_powers = [(a,) for a in A]
for j in range(k-1):
cartesian_powers = [ i+(a,) for i in cartesian_powers for a in A]
print("Tuples in {}^{}: {}".format(A,k,set(cartesian_powers)))
print("Size = {}".format(len(cartesian_powers)))