Question: Make a function to count the longest consecutive numbers in list. for example, if the list1 is [1, 3, 4, 5, 6] the longest

Make a function to count the longest consecutive numbers in list.

 

for example, if the list1 is [1, 3, 4, 5, 6]

the longest consecutive numbers are [4, 5, 6]

and the length of the numbers is 3

so the answers should be 3

 

the numbers in the list1 can increase or decrease.

 

 

The format should be like

 

def longest_run(list1)

...(statement)

...

...

return largest_length

 

if there is no consecutive number, it should return '1'

Step by Step Solution

3.31 Rating (145 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

python def longestrunlist1 count 1 Initialize count to 1 maxcount 1 Initialize maxcount to ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!