Skip to content

Instantly share code, notes, and snippets.

@jonathanpike
Last active August 29, 2015 14:23
Show Gist options
  • Save jonathanpike/3343a66c3d57b3538bec to your computer and use it in GitHub Desktop.
Save jonathanpike/3343a66c3d57b3538bec to your computer and use it in GitHub Desktop.
# from http://www.practicepython.org/exercise/2014/04/10/10-list-overlap-comprehensions.html
import random
# a = random.sample(range(1,1000), 20)
# b = random.sample(range(1,1000), 30)
a = [1, 1, 3, 5, 6, 7, 8, 10]
b = [1, 1, 6, 7, 10, 14, 17, 18]
a.sort()
b.sort()
print a
print b
new_list = [x for x in a and b if x in a and x in b]
print new_list
result = []
for i in new_list:
if i in result:
pass
else:
result.append(i)
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment