Home / Expert Answers / Computer Science / python-define-a-function-called-get-longest-length-values-list-which-takes-a-list-of-integers-as-pa715

(Solved): python Define a function called get_longest_length (values_list) which takes a list of integers as ...



Define a function called get_longest_length (values_list) which takes a list of integers as input. The function should calculpython

Define a function called get_longest_length (values_list) which takes a list of integers as input. The function should calculate and return the length of the longest consecutive sequence of non-zero values in the list. For example, consider the following list: values = [3, 6, 12, 0, 0, 9, 10, 5, 5, 0, 2, 1, 3, 0, 9] There are four distinct sequences of values in this list that are separated by zero values: 3, 6, 12 (this is of length 3) 9, 10, 5, 5 (this is of length 4) 2, 1, 3 (this is of length 3) 9 (this is of length 1) In this case, the length of the longest sequence is 4, so the function should return 4. You can assume that the input list contains at least one non-zero integer. For example: Test Result result = get_longest_length([3, 6, 12, 0, 0, 9, 10, 5, 5, 0, 2, 1, 3, 0, 9]) 4 print (result) 1 result = get_longest_length([100]) print (result)


We have an Answer from Expert

View Expert Answer

Expert Answer


Dear student below is the code snippet in Python, explained in detail: '''approach:- first, check whether if any zero is present in list or not, if not then will return the length of list if zero present: we will find the index of zero element in the
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe