【发布时间】:2019-11-04 20:12:37
【问题描述】:
列表推导[j-x[i]==0 for i,j in enumerate(x[1:])] 将生成一个布尔元素列表。返回值必须是布尔标量而不是列表。它是通过对所有元素进行 OR-ing 获得的。该怎么做?
def has_same_adjecent(x):
if len(x)<2:
return False
return [j-x[i]==0 for i,j in enumerate(x[1:])]
has_same_adjecent([3,1,3,3])# must return True
【问题讨论】: