append tuples to a list

前端 未结 4 1870
鱼传尺愫
鱼传尺愫 2021-02-13 00:46

How can I append the content of each of the following tuples (ie, elements within the list) to another list which already has \'something\' in it? So, I want to append the follo

4条回答
  •  伪装坚强ぢ
    2021-02-13 01:06

    You can convert a tuple to a list easily:

    >>> t = ('AAA', 1.11)
    >>> list(t)
    ['AAAA', 1.11]
    

    And then you can concatenate lists with extend:

    >>> t = ('AAA', 1.11)
    >>> result = ['something']
    >>> result.extend(list(t))
    ['something', 'AAA', 1.11])
    

提交回复
热议问题