Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing tuples within tuples?

I've got a python function that should loop through a tuple of coordinates and print their contents:

def do(coordList):
    for element in coordList:
        print element
y=((5,5),(4,4))
x=((5,5))

When y is run through the function, it outputs (5,5) and (4,4), the desired result. However, running x through the function outputs 5 and 5.

Is there a way to force x to be defined as a tuple within a tuple, and if not, what is the easiest way to resolve this problem?

like image 812
Bibendum Avatar asked Jul 05 '26 10:07

Bibendum


1 Answers

Use a trailing comma for singleton tuples.

x = ((5, 5),)
like image 62
sykora Avatar answered Jul 06 '26 23:07

sykora



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!