我需要按顺序迭代,直到找到或最大化。例如:
ds = [1,2,3,4,5,6,7,8,9]
tmp = 3 # start (variable)
max = 5 # maximize (variable)
target = 8
所以输出:[4,5,6,7,8] 对不起,我的英语不好。
作为一种非常简单的方法,您可以使用相同的列表对串联进行索引。
但是,从内存的角度来看肯定不是最好的解决方案。
# ds = [1,2,3,4,5,6,7,8,9]
start = 4
length = 7
res = (ds + ds)[start:start+length]
# [5, 6, 7, 8, 9, 1, 2]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句