Guest User

Untitled

a guest
Jul 23rd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. import random
  2.  
  3. m = [5,2,6,9,5,2,65,6,5,5,5,5,5]
  4. k = [x for x in range(0,random.randint(0,90))] # using random.randint() to generate a random list
  5.  
  6. common_list = [x for x in m for y in k if x == y] # using list comprehension to seek common elements from the list
  7.  
  8. new_set = set(k) # using the set constructor to convert the list into the set so there will be no duplicatopn of the element
  9.  
  10. final_list = list(new_set) # converting back into list
  11.  
  12. print(final_list)
Advertisement
Add Comment
Please, Sign In to add comment