a = ((), (), (5, 5, 5), (), (3), (), ())
[list(x) for x in a]
Expected output [[], [], [5, 5, 5], [], [3], [], []]
but got
TypeError: 'int' object is not iterable
CodePudding user response:
What you have is not a tuple.
Use (3,)
instead of (3)
to create a tuple, otherwise Python thinks it's an expression and returns 3
.
CodePudding user response:
You are missing a comma in (3). The correct code would be:
a = ((), (), (5, 5, 5), (), (3,), (), ())
[list(x) for x in a]
CodePudding user response:
I tried a = ((), (), (5, 5, 5), (), (3), (), ()) [tuple(x) for x in a]
I got TypeError: 'int' object is not iterable. Is there a method to convert it to (3,)?