I have a tuple of tuples in the form:
test=((-1.0, 1.0, 0.0),
(-1.0, -1.0, 0.0),
(1.0, -1.0, 0.0),
(1.0, 1.0, 0.0))
I would like to name each tuple in a loop as:
Desired Output:
coord1 = (-1.0, 1.0, 0.0)
coord2 = (-1.0, -1.0, 0.0)
coord3 = (1.0, -1.0, 0.0)
coord4 = (1.0, 1.0, 0.0)
Not sure how to implement this for a variable amount of assignments. i.e., my tuple of tuples has a length of 604.
>Solution :
You can try this for more coord as you say you have 604 coords:
test=((-1.0, 1.0, 0.0),(-1.0, 1.0, 0.0),
(-1.0, -1.0, 0.0),(-1.0, -1.0, 0.0),
(1.0, -1.0, 0.0),(1.0, -1.0, 0.0),
(1.0, 1.0, 0.0),(1.0, 1.0, 0.0))
coors = map(lambda x: f'Coords {x}', range(len(test)))
res = zip(coors, test)
print(*(map(lambda x: f'{x[0]} = {x[1]}', res)), sep = '\n')
Output:
Coords 0 = (-1.0, 1.0, 0.0)
Coords 1 = (-1.0, 1.0, 0.0)
Coords 2 = (-1.0, -1.0, 0.0)
Coords 3 = (-1.0, -1.0, 0.0)
Coords 4 = (1.0, -1.0, 0.0)
Coords 5 = (1.0, -1.0, 0.0)
Coords 6 = (1.0, 1.0, 0.0)
Coords 7 = (1.0, 1.0, 0.0)