簡體   English   中英

我如何 select 列表的元素從列表中的后一個元素開始到 python 之前的元素

[英]How can I select elements of a list starting by a later element in the list to one that is before in python

我的問題是,如何 select 列表的多個元素,但從列表的后一個元素開始到之前的一個元素,例如:

list_1 = [1, 2, 3, 4, 5, 6, 7, 8]

list_2 = list_1[6:3]

print(list_2)

# Result

[7, 8, 1, 2, 3]
list_1 = [1, 2, 3, 4, 5, 6, 7, 8]
list_2 = list_1[6:]+list_1[:3]
print(list_2)

回報:

[7, 8, 1, 2, 3]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM