Skip to content

Instantly share code, notes, and snippets.

@jonathanpike
Last active August 29, 2015 14:23
Show Gist options
  • Save jonathanpike/b90c628a717d2fd9ae00 to your computer and use it in GitHub Desktop.
Save jonathanpike/b90c628a717d2fd9ae00 to your computer and use it in GitHub Desktop.
# from http://www.practicepython.org/exercise/2014/04/25/12-list-ends.html
import random
def first_and_last(l):
new_list = l[::len(l)-1]
""" This specifies the "step" -- takes the first item,
skips the length of the list less 1, and therefore gives
you the last item """
print new_list
a = [5, 10, 15, 20, 25]
b = random.sample(range(1, 20), random.randrange(2, 10))
first_and_last(a)
first_and_last(b)
print b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment