← Back to challenges

Return the First and Last Elements in a List

PythonMediumarraysvalidationlanguage_fundamentals

Instructions

Create a function that takes a list of values and returns the first and last values in a new list.

Examples

first_last([5, 10, 15, 20, 25]) ➞ [5, 25]

first_last(["edabit", 13, None, False, True]) ➞ ["edabit", True]

first_last([None, 4, "6", "hello", None]) ➞ [None, None]

Notes

  • Test input will always contain a minimum of two elements within the list.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Destructuring Assignment (Ignoring Values)