Question 1
Write a function double_ends(l) that takes a list l (with at least two elements) and returns a new list where the first and last elements of l are duplicated at the beginning and end of the list, respectively.
The new list should have:
The first element of the original list inserted once at the beginning The last element of the original list inserted once at the end
You must not modify the original list.
Constraints
The input list will contain at least two elements
The list can contain elements of any type (integers, strings, etc.)
NOTE: This is a function type question, you don't have to take input or print the output, just have to complete the required function definition.
Example
>>> double_ends([10, 20, 30])
[10, 10, 20, 30, 30]
>>> double_ends(['a', 'b', 'c'])
['a', 'a', 'b', 'c', 'c']
>>> double_ends([1, 2])
[1, 1, 2, 2]
>>> double_ends([5, 6, 7, 8])
[5, 5, 6, 7, 8, 8]
Your task
Implement this function:
def double_ends(l: list) -> list:
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: l.
Example
Input
[10, 20, 30]
Output
[10, 10, 20, 30, 30]