我正在尝试使用Python.我想在几个列表(L [i])中切片列表(高原),但我有以下错误消息:
File "C:\Users\adescamp\Skycraper\skycraper.py", line 20, in <module>
item = plateau[debut:fin]
TypeError: slice indices must be integers or None or have an __index__ method
Run Code Online (Sandbox Code Playgroud)
有关线是与之相关的 item = plateau[debut:fin]
from math import sqrt
plateau = [2, 3, 1, 4, 1, 4, 2, 3, 4, 1, 3, 2, 3, 2, 4, 1]
taille = sqrt(len(plateau))
# Division en lignes
L = []
i = 1
while i < taille:
fin = i * taille
debut = fin - taille
item = plateau[debut:fin] …Run Code Online (Sandbox Code Playgroud) 如何检测无限序列中的重复数字?我试过Floyd&Brent检测算法,但什么都没有......我有一个生成器,产生0到9(含)的数字,我必须认识到它的一个时期.
示例测试用例:
import itertools
# of course this is a fake one just to offer an example
def source():
return itertools.cycle((1, 0, 1, 4, 8, 2, 1, 3, 3, 1))
>>> gen = source()
>>> period(gen)
(1, 0, 1, 4, 8, 2, 1, 3, 3, 1)
Run Code Online (Sandbox Code Playgroud)