Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. def every_third(original_list):
  2. """(list) -> (list)
  3.  
  4. Takes the original_list list and returns a new list consisting of every
  5. third element in the original_list. Function will use a while loop.
  6.  
  7. >>>every_third([10, 5, 8, 12, 4, 16])
  8. [8, 16]
  9. """
  10. new_list = []
  11. counter = 0
  12. while counter <= len(original_list):
  13. if (original_list[counter + 1] % 3) == 0:
  14. new_list.append(original_list[counter])
  15. counter = counter + 1
  16. return new_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement