Advertisement
dvdjaco

8.1

Feb 18th, 2012
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. # #!/usr/bin/python
  2. #
  3. # By dvdjaco
  4. # Exercise 8.1
  5. #
  6. # Write a function called chop that takes a list and modifies it, removing the first  and last elements, and returns None.
  7. # Then write a function called middle that takes a list and returns a new list that contains all but the first and last elements.
  8.  
  9. def chop(l):
  10.     del l[0]
  11.     del l[len(l)-1]
  12.     return None
  13.  
  14. def middle(l):
  15.     return l[1:len(l)-1]
  16.    
  17. l = [10,11,12,13,14]
  18. print l
  19. chop(l)
  20. print l
  21.  
  22. l = [10,11,12,13,14]
  23. print l
  24. print middle(l)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement