Python: A program to find the LENGTH of the longest run in a given list?

后端 未结 6 2278
南方客
南方客 2020-12-03 12:59

Q: A run is a sequence of adjacent repeated values. Given a list, write a function to determine the length of the longest run. For example, for the sequence [1, 2, 5, 5, 3,

6条回答
  •  眼角桃花
    2020-12-03 13:39

    def longestrun(myList):
        size = 1
        max_size = 0
        for i in range(len(myList)-1):
            if myList[i+1] = myList[i]:
                size += 1
            else: 
                size = 1
            if max_size

    Remove the .split() from myList in main() and you're good to go with this.

提交回复
热议问题