How to insert the contents of one list into another

前端 未结 3 372
借酒劲吻你
借酒劲吻你 2020-12-29 02:16

I am trying to combine the contents of two lists, in order to later perform processing on the entire data set. I initially looked at the built in insert functi

3条回答
  •  無奈伤痛
    2020-12-29 02:37

    insert(i,j), where i is the index and j is what you want to insert, does not add as a list. Instead it adds as a list item:

    array = ['the', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']
    array.insert(1,'brown')
    

    The new array would be:

    array = ['the', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']
    

提交回复
热议问题