相关疑难解决方法(0)

切片索引必须是整数或无或具有__index__方法

我正在尝试使用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)

python slice

50
推荐指数
1
解决办法
15万
查看次数

检测未知来源的时间段

如何检测无限序列中的重复数字?我试过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)

python algorithm math floyd-cycle-finding

7
推荐指数
1
解决办法
4844
查看次数

标签 统计

python ×2

algorithm ×1

floyd-cycle-finding ×1

math ×1

slice ×1