Skip to content

Instantly share code, notes, and snippets.

@cjshaw1976
Created June 6, 2016 04:23
Show Gist options
  • Save cjshaw1976/657dc02b40d2a98bdaa20c3672544569 to your computer and use it in GitHub Desktop.
Save cjshaw1976/657dc02b40d2a98bdaa20c3672544569 to your computer and use it in GitHub Desktop.
'''
05.py: Exercise 05 from practicepython.org.
Take two lists and write a program that returns a list that contains only the elements that are common between the lists (without duplicates).
'''
__author__ = "Christopher J Shaw"
import random
list1=[]
list2=[]
for _ in range(20):
num1 = random.randrange(0, 99)
if num1 not in list1:
list1.append(num1)
num2 = random.randrange(0, 99)
if num2 not in list2:
list2.append(num2)
print(list1)
print(list2)
common = []
for num in list1:
if num in list2:
common.append(num)
print(common)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment