简体   繁体   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

my question is, how to select multiple elements of a list but starting on a later element of a list to one element that is before, for example:我的问题是,如何 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)

Returns:回报:

[7, 8, 1, 2, 3]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python - 如何从第一个元素开始从列表中一个一个打印元素并递增直到最后一个 - How can I print an element from a list one by one starting by first element and increment until the last one in python 在Python中,如何在元素列表中搜索值,然后在其之前获取元素? - In Python, how can I search a list of elements for a value then also take the element before it? Python:如何在最长元素之前获取列表中的所有元素? - Python:How can i get all the elements in a list before the longest element? 如何在列表元素之前和之后放置一个空格? - How I can put one space before and after list elements? 如何测试一个列表的两个元素,如果它们相等,则将一个列表的元素放到新列表中 - How can I test two elements of one list and if they are equivalent place the element of one list into a new list 如何基于python中的优先级列表选择列中的元素? - How can I select elements in a column based on a priority list in python? 如何检查数字是否可以被列表中的元素之一整除(Python)? - How can I check if a number is divisible by one of the elements in a list (Python)? 如何计算列表中某个元素之前的特定元素? - How to count specific elements before an element in a list? Python:如何将列表的一个元素与除自身之外的所有其他元素进行比较? - Python: How do I compare one element of a list with every other elements besides itself? Python列表包含3个元素,但我只能访问最后一个元素 - Python list has 3 elements but I can only access the last element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM