python list concatenation efficiency

前端 未结 6 1389
陌清茗
陌清茗 2020-12-16 13:07

What is the most efficient way to concatenate two lists list_a and list_b when:

  • list_b items have to be placed before
6条回答
  •  心在旅途
    2020-12-16 13:21

    You can assign list_b to a slice, which happens to be empty but at the start of list_a:

    list_a[0:0] = list_b
    

    This is the fastest way to insert a list into another list, at any position.

提交回复
热议问题