Advertisement
Abdullah_Bin_Madawi

Untitled

Aug 12th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. q4
  2. def pop_random_element(self, the_list):
  3. """This method picks a random element from a list, removes that
  4. element from the list and returns the element.
  5.  
  6. Note: the pop() function might be useful here
  7. """
  8.  
  9. popped = the_list.pop(random.randint(0,len(the_list)-1))
  10. return(popped)
  11. --------------------------------------------------
  12. q5
  13. def append_unique(self, src, dst):
  14. """This method appends the elements of the src list to the dst list,
  15. but only if they are not already in the dst list. In other words, the
  16. dst list is increased by adding new elements from the src list.
  17. """
  18. for i in src:
  19. if i not in dst:
  20. dst.append(i)
  21.  
  22. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement