I want Python to convert all 3D lists to tuple

Asked 1 years ago, Updated 1 years ago, 417 views

I would like to convert the 3D list into a tuple as shown below, but what should I do?

obj1=[[[1,2],[3,4]],[[5,6],[7,8]]]
obj2=(((1,2),(3,4)),((5,6),(7,8))))

Thank you for your cooperation.

python python3

2023-03-05 12:59

1 Answers

obj2=tuple(map(lambdai:tuple(map(tuple,i))),obj1)
print(obj2)

# (((1, 2), (3, 4)), ((5, 6), (7, 8)))


2023-03-06 09:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.