For the problem below, I am practicing the set() data type. The first problem was easy, so I wanted to try using randomly generated lists to practice something more difficult.
Unlike the first program, which returns {1, 2, 3, 5, 8, 13}
, my randomly-generated list program returns solely set()
Why would this be? Is there a condition of the random import that I’m not understanding?
Code is below.
Thanks!
import random
#write a program that returns a list that contains
# only the elements that are common between the lists (without duplicates).
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
new_set = set(a).intersection(b)
print(new_set)
#perform same program but with randomly generated lists
list_a = random.sample(range(100), 5)
list_b = random.sample(range(100), 5)
random_set = set(list_a).intersection(list_b)
print(random_set)