Python Periksa apakah array bergantian

def alternating(list):
  for i  in range(1,len(list)):
    if (((list[i]>list[i+1]) and (list[i]>list[i-1])) or ((list[i]  <list[i+1]) and (list[i]<list[i-1]))) :
      return True
    else:
      return False
Mattis Cauwel