M.Sc Python Programming Assignments
Assignment 13
Question:
Write a program that takes a list of numbers (for example, a = [5, 10, 15, 20, 25])and makes a new list of only the first and last elements of the given list.
Code:
def extract_first_and_last(numbers):
if len(numbers) >= 2:
return [numbers[0], numbers[-1]]
else:
return numbers
# Example list
a = [5, 10, 15, 20, 25]
new_list = extract_first_and_last(a)
print("New list:")
print(new_list)
Output:
Name counts:
lucifer: 1