Skip to content

Instantly share code, notes, and snippets.

@pinkpretty
Created September 20, 2016 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinkpretty/ac7ace0e48d519456cd59c1e4a97465a to your computer and use it in GitHub Desktop.
Save pinkpretty/ac7ace0e48d519456cd59c1e4a97465a to your computer and use it in GitHub Desktop.
'''
this is practice python 5th exercise
'''
'''
Take two lists, say for example these two:
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]
and write a program that returns a list that contains only the elements that are common between the lists (without duplicates). Make sure your program works on two lists of different sizes.
Extras:
1.Randomly generate two lists to test this
2.Write this in one line of Python
'''
import random
my_random1 = [random.randrange(1,101) for _ in range (10)]
my_random2 = [random.randrange(1,101) for _ in range (10)]
common_elements = []
print(my_random1)
print(my_random2)
for item in my_random1 and my_random2:
if item in my_random1 and my_random2:
common_elements.append(item)
print(common_elements)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment