Skip to content

Instantly share code, notes, and snippets.

@jgarciabu
Created July 31, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgarciabu/45e436b2c87cf067ac669014932b2fde to your computer and use it in GitHub Desktop.
Save jgarciabu/45e436b2c87cf067ac669014932b2fde to your computer and use it in GitHub Desktop.
First and Last Ex 12
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
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.
@author: Jeff Garcia
"""
userlist = input("Please enter a list of numbers separated by a single space:")
userlist = list(map(int,userlist.split()))
def list_first_and_last(userlist):
newlist = []
newlist.append(userlist[0])
newlist.append(userlist[-1])
return newlist
print(list_first_and_last(userlist))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment