As mentioned, a run is a sequence of consecutive repeated values. Implement a Python function called longest_run that takes a list of numbers and returns the length of the longest run. For example in the sequence:
2, 7, 4, 4, 2, 5, 2, 5, 10, 12, 5, 5, 5, 5, 6, 20, 1 the longest run has length 4. Then, in the main, your program should ask the user to input the list, then it should call longest_run function, and print the result.
This is what I tried but it only returns 1 and I don't understand why. I can't import any modules for this question.
def longest_run(aList):
'''(list)->int
Returns length of the longest run
Precondition: aList is a list of a len of at least 2 and elements of list are ints
'''
count=0
bucket=[]
for i in aList:
if bucket==i:
count=count+1
else:
bucket=i
count=1
return count