I have a list like this:
list = [(1,'abc'),0.312,(2,'def'),0.122,(1,'abc'),0.999]
I want to merge element(1, 'abc')
with 0.312
, so the output should like:
list = [(1,'abc',0.312),(2,'def',0.122),(1,'abc',0.999)]
Any one can help me with it? Many thanks!
Use a list comprehension to build the new tuple after zipping your list items in twos:
l = [i+(j,) for i, j in zip(lst[::2], lst[1::2])]
print(l)
# [(1, 'abc', 0.312), (2, 'def', 0.122), (1, 'abc', 0.999)]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments