简体   繁体   English

如何从位于 3 索引的倍数的列表中获取所有数字

[英]How to get all numbers from list which are located at multiple of 3 index

How to get all numbers from list which are located at multiple of 3 index for example例如,如何从位于 3 索引的倍数的列表中获取所有数字

li=['ab','ha','kj','kr','op','io']

i need我需要

['kj','io']

Use slicing on list where [2::3] means start from 2nd index(indices start from 0 in python) and get every 3rd element在列表上使用slicing ,其中[2::3]表示从第二个索引开始(索引从 0 在 python 中开始)并获取每个第三个元素

print(li[2::3])

Output: Output:

['kj','io']
for index,i in enumerate(li):
    index = index+1
    if index % 3 == 0: print(i)

How to get all numbers from list which are located at multiple of 3 index for example例如,如何从列表中获取位于 3 个索引的倍数的所有数字

li=['ab','ha','kj','kr','op','io']

i need我需要

['kj','io']

暂无
暂无

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

相关问题 如何从位于列表中的相应索引名称中过滤列表值? - How to filter list values from corresponding index names located in list? 从 1 到 8 不按升序排列的唯一数字的输入列表中获取开始和结束索引的方法是什么 - What is the way to get the starting and ending index from an input list of unique numbers from 1 to 8 which are not in ascending order 有关数字列表和间隔列表,请查找每个数字所在的时间间隔 - For a list of numbers and a list of intervals, find the interval in which each number is located 使用 python for 循环打印列表中不按索引顺序排列的数字 - Using a python for loop to print numbers from a list which are not in order of their index 如何更有效地获取列表中所有记录最高数字的索引值? - How do I more efficiently get a list's index values for all its record highest numbers? 如何从 Lucene 8.6.1 索引中获取所有令牌的列表? - How to get a list of all tokens from Lucene 8.6.1 index? 从数字列表中获取所有可能的产品 - Get all of the possible products from a list of numbers 如何从带有数字的列表中删除索引? - How to remove an index from a list with numbers? Python - 获取列表的索引,所有进一步的条目都满足条件 - Python - get index of list from which on all further entries satisfy condition 如何将特定定位的文本放入数据框索引中? - How to get an specific located text into a dataframe index?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM