append tuples to a list

前端 未结 4 1883
鱼传尺愫
鱼传尺愫 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:19

    You can use the inbuilt list() function to convert a tuple to a list. So an easier version is:

    l = [('AAAA', 1.11), ('BBB', 2.22), ('CCCC', 3.33)]
    result = [list(t) for t in l]
    print result
    

    Output:

    [['AAAA', 1.1100000000000001],
     ['BBB', 2.2200000000000002],
     ['CCCC', 3.3300000000000001]]
    

提交回复
热议问题