+ 2
python question
i have this list: a=[1,2,3,4] i want print in terminal: [((1,2),(3,4))] and my another list:b=[1,2,3,4,5] i want print in terminal: ((1,2),(3,4)),5)
2 Answers
+ 6
Parham Shafiei Sabet ,
your suggested output is not complete clear:
âȘïžin the first option you will have 2 tuples inside an other tuple which is inside a list:
[((1,2),(3,4))]
âȘïžin the second option will have 2 tuples inside an other tuple with a trailing closing parenthesis, which is not balanced and has no list around.
((1,2),(3,4)),5)
0
This may help You.......
a=[1,2,3,4]
x,y=[],[]
for i in range(2):
x.append(a[i])
for i in range(2,4):
y.append(a[i])
z=(tuple(x),tuple(y))
print([z])