嗨,我有这段代码,并试图将其重构为声明性的。但是AFAIK,所有像这样的声明性方法map()
reduce()
filter()
都会循环遍历容器的每个元素,而不是像这样
def arrayCheck(nums):
# Note: iterate with length-2, so can use i+1 and i+2 in the loop
for i in range(len(nums)-2):
# Check in sets of 3 if we have 1,2,3 in a row
if nums[i]==1 and nums[i+1]==2 and nums[i+2]==3:
return True
return False
那么如何编写这段代码,声明式的方式呢?