[(1, 2), (3, 4)] how can I add element of 2nd tuple of list into 1st tuple ? I want the final output as : [(1,2,3,4)]
Asked
Active
Viewed 65 times
0
-
2Just a small note: those are *tuples*, not *sets*. – Carcigenicate May 25 '20 at 19:38
3 Answers
1
Just try itertools
import itertools
out = [tuple(itertools.chain.from_iterable(ls))]
or else, If you want the lambda function please try below:
flatten = lambda l: [tuple([item for sublist in l for item in sublist])]
flatten(ls)
Basically, you cannot edit or add the elements, but you can create a tuple by iterating the values inside tuples.

Vanarajan Natarajan
- 145
- 1
- 7
0
In the simple case, that's the simple solution:
l = [(1, 2), (3, 4)]
res = [l[0] + l[1]]
result:
[(1, 2, 3, 4)]

Roy2012
- 11,755
- 2
- 22
- 35
0
first iteration for and inner for for elements.
x = [(1, 2), (3, 4)]
y=[]
for i in x:
for e in i:
y.append(e)
print(y)

melihuyelik
- 46
- 3