【发布时间】:2021-03-27 13:06:52
【问题描述】:
我想生成一个仅包含 Python 整数的奇数索引的列表。
这是我尝试做的:
number = 5167460267890853
numberList = [num for num in str(number)]
oddIndex = [num for num in numberList if numberList.index(num) % 2 == 0]
print(oddIndex)
输出:
['5', '6', '4', '6', '0', '6', '8', '0', '8', '5']
预期输出:
['5', '6', '4', '0', '6', '8', '0', '5']
【问题讨论】:
标签: python python-3.x list