+ 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)

19th Dec 2021, 9:05 AM
Parham Shafiei Sabet
Parham Shafiei Sabet - avatar
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)
19th Dec 2021, 5:00 PM
Lothar
Lothar - avatar
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])
19th Dec 2021, 9:29 AM
Ravi V
Ravi V - avatar