Created
September 20, 2016 07:58
-
-
Save pinkpretty/ac7ace0e48d519456cd59c1e4a97465a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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