7
可能嗎?顯然x[1:-1].sort()
不起作用,因爲該切片是副本。就地排序的子列表
當前的解決辦法:
>>> x = [4, 3, 1, 2, 5]
>>> s = slice(1, -1)
>>> x[s] = sorted(x[s])
>>> x
[4, 1, 2, 3, 5]
我可以以某種方式得到一個Python列表上視圖?
可能嗎?顯然x[1:-1].sort()
不起作用,因爲該切片是副本。就地排序的子列表
當前的解決辦法:
>>> x = [4, 3, 1, 2, 5]
>>> s = slice(1, -1)
>>> x[s] = sorted(x[s])
>>> x
[4, 1, 2, 3, 5]
我可以以某種方式得到一個Python列表上視圖?
相關:[我可以在Python列表創建一個「視圖?」](http://stackoverflow.com/questions/3485475/can-i-create-a-view-on-a-python-list) –
見http://www.shaunlippy.org/blog/?p=77 – user1929959
現在有一個python afaik列表,因爲它存在字典(dict.viewkey等)。我在列表中沒有看到任何用於查看的用例,那麼您認爲它的含義是什麼?它應該提供什麼? ('''b = x'''可能是某種觀點,儘管它是無用的)。 – dorvak