Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to name each tuple in a for loop

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading