我是编码的新手,并且希望避免迭代问题中的for循环,以使我的代码获得更好的运行时间。
for k in range(1,k+1):
for dates in times:
x,y = dates
count = 1
for i in times[times.index(dates):]:
comp_date = i
x = comp_date[0]
if y <= x:
count += 1
y = comp_date[1]
有人有想法吗?谢谢!
对您要达到的目标有更多的了解。
代替嵌套这些循环,您可以依次运行它们,但这实际上取决于您使用的数据结构。