Panhary H.

asked • 03/03/23

Write a function get_last(nested_list) that takes in a list of lists of integers

Write a function get_last(nested_list) that takes in a list of lists of integers, and returns a list containing the last integer in each inner list. If one of the inner lists is empty, then a 0 should be placed into the output list instead of the last element (since an empty list doesn't have a last element.

Examples: >>> get_last([[6, 3, 25, 4], [], [22, 16, 38]]) [4, 0, 38]

>>> get_last([[2]]) [2]

>>> get_last([[-20, 10, 2, 4, 5], [4], [8, 25, 10], []]) [5, 4, 10, 0]


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.