how to add value to a tuple?

后端 未结 8 1712
别那么骄傲
别那么骄傲 2020-12-08 03:43

I\'m working on a script where I have a list of tuples like (\'1\',\'2\',\'3\',\'4\'). e.g.:

list = [(\'1\',\'2\',\'3\',\'4\'),
        (\'2\',\         


        
8条回答
  •  孤城傲影
    2020-12-08 04:21

    Based on the syntax, I'm guessing this is Python. The point of a tuple is that it is immutable, so you need to replace each element with a new tuple:

    list = [l + (''.join(l),) for l in list]
    # output:
    [('1', '2', '3', '4', '1234'), 
     ('2', '3', '4', '5', '2345'), 
     ('3', '4', '5', '6', '3456'), 
     ('4', '5', '6', '7', '4567')]
    

提交回复
热议问题