Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multidimensional array to multidimensional tuple

If I have an array such:

inner_loop = 
[
 [
  [18, 119], [42, 119], [42, 95], [18, 95]
 ],
 [
  [80, 96], [80, 75], [59, 75], [59, 96]
 ]
]

how do I convert it to a multidimensional tuple like

(
 (
  (18, 119), (42, 119), (42, 95), (18, 95)
 ),
 (
  (80, 96), (80, 75), (59, 75), (59, 96)
 )
)

I have tried:

tuple(tuple(y) for y in (tuple(tuple (x) for x in (tuple(inner_loops)))))

but the last level is not converted.

like image 857
Rojj Avatar asked Nov 07 '25 06:11

Rojj


1 Answers

tuple(tuple(tuple(l2) for l2 in l1) for l1 in inner_loop)
like image 51
Mohammad Al Alwa Avatar answered Nov 09 '25 22:11

Mohammad Al Alwa



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!