I'd like to build one of these lists of tuples:
(a, 0), (-a, 0) (b, 0), (-b, 0)(0, a), (0, -a) (0, b), (0, -b)
from scalars a and b.
based on a condition:
c = a > b
This is my attempt:
a = 5
b = 2
c = a > b
# Try build two tuples per element, e.g. (5, 0), (-5, 0) (2, 0), (-2, 0)
# This syntax is illegal
#f2 = [(m,0), (-m,0) if c else (0,m), (-0,-m) for m in (a,b)]
# This syntax works but creates tuples of tuples
f2 = [tuple(((m,0), (-m,0))) if c else tuple(((0,m), (-0,-m))) for m in (a,b)]
print(*f2) # ((5, 0), (-5, 0)) ((2, 0), (-2, 0))
# This syntax is illegal
#f3 = [*tuple(((m,0), (-m,0))) if c else *tuple(((0,m), (-0,-m))) for m in (a,b)]
#print(*f3)
f2 builds a list of two tuples of two tuples: ((5, 0), (-5, 0)) ((2, 0), (-2, 0)).
Using * operator in f3 to unpack the outer tuples triggers a syntax error.
What is the correct syntax?
Also I don't understand why f2 is ((5, 0), (-5, 0)) ((2, 0), (-2, 0)), where the outer tuples are not separated by a ,?