Question: python Write a function left_sublist_sum(lst, m), that returns the first sublist of lst that sums exactly to m. Otherwise, it should return None if no
python
Write a function left_sublist_sum(lst, m), that returns the first sublist of lst that sums exactly to m. Otherwise, it should return None if no such sublist exists.
Function header: left_sublist_sum(lst, m)
Input: a list lst with numeric elements and a number m.
Output: the first (left-most) sublist that sums exactly to m or None if no such sublist exists.
Examples:
>>> left_sublist_sum([ 1, 8, 5, 10], 9)
[1, 8]
>>> left_sublist_sum([ -5, -2, 4, 11], 15)
[4, 11]
>>> left_sublist_sum([3, 7, 2, 3], 12)
[3, 7, 2]
>>> left_sublist_sum([5, 9, -1, 2], 9)
[9]
>>> left_sublist_sum([5, 9, -1, 2], 7)
None
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
