Apr-19-2019, 10:38 AM
Hello
I am currently writing a piece of code that creates a list from the numbers that 2 other lists have in common (excluding duplicates).
It was nice and simple when I input actual lists to use.
e.g. 2 lists of [1,1,2,3] and [1,3,4] would makes a list of just [1,3]
However, now that the lists are randomly generated, it returns an empty list as if they have no numbers in common.
Code below
Soup
I am currently writing a piece of code that creates a list from the numbers that 2 other lists have in common (excluding duplicates).
It was nice and simple when I input actual lists to use.
e.g. 2 lists of [1,1,2,3] and [1,3,4] would makes a list of just [1,3]
However, now that the lists are randomly generated, it returns an empty list as if they have no numbers in common.
Code below
import random a = [random.sample(range(1,100), 50)] b = [random.sample(range(1,100), 50)] y=[] for i in a: if i in y: continue for l in b: if i == l: y = y + [i] print(y)Thanks for the help!
Soup