Skip to content

Instantly share code, notes, and snippets.

@xsaamiir
Last active October 14, 2017 14:41
Show Gist options
  • Save xsaamiir/9de5ce13745d97ebb34168e6c7acd250 to your computer and use it in GitHub Desktop.
Save xsaamiir/9de5ce13745d97ebb34168e6c7acd250 to your computer and use it in GitHub Desktop.
""" A program that returns a list that contains only the elements that are common between the lists (without duplicate).
The program should work with list of different sizes"""
import itertools
import random
a = random.sample(range(100), 50)
b = random.sample(range(200), 10)
#a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 8]
#b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
def intersection(a, b):
return list(set(x for x in a for y in b
if x == y))
print(intersection(a, b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment