Python: create sublist without copying

前端 未结 4 1006
执笔经年
执笔经年 2021-02-13 16:35

I have a question about how to create a sublist (I hope this is the right term to use) from a given list without copying.

It seems that slicing can create sublists, but

4条回答
  •  不要未来只要你来
    2021-02-13 17:16

    you can't if you slice a to get b.

    All slice operations return a new list containing the requested elements. This means that the following slice returns a new (shallow) copy of the list [1]

    [1] https://docs.python.org/2/tutorial/introduction.html

提交回复
热议问题