Last active
August 29, 2015 14:23
-
-
Save jonathanpike/b90c628a717d2fd9ae00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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