Guest User

Untitled

a guest
Nov 17th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. """
  2. write a program that returns a list that contains only the elements that are common between the lists
  3. (without duplicates). Make sure your program works on two lists of different sizes.
  4. Extras:
  5.  
  6. Randomly generate two lists to test this.
  7. Write this in one line of Python.
  8. """
  9. import random
  10.  
  11. a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
  12. b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
  13. c = []
  14.  
  15. for i in a: #for anything in a do:
  16. if i in b: #if any of a values are in b, do:
  17. c.append(i) #add each iterated value to list c.
  18.  
  19. print(c)
Add Comment
Please, Sign In to add comment