Practice Python

Beginner Python exercises

15 May 2014

List Ends Solutions

Exercise 12

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. For practice, write this code inside a function.

Sample solution

def list_ends(a_list):
return [a_list[0], a_list[len(a_list)-1]]
view raw gistfile1.py hosted with ❤ by GitHub

Enjoying Practice Python?


Explore Yubico
Explore Yubico