How to insert the contents of one list into another

前端 未结 3 376
借酒劲吻你
借酒劲吻你 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:53

    You can do the following using the slice syntax on the left hand side of an assignment:

    >>> array = ['the', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog']
    >>> array[1:1] = ['quick', 'brown']
    >>> array
    ['the', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog']
    

    That's about as Pythonic as it gets!

提交回复
热议问题