Created
May 16, 2017 14:58
-
-
Save ehedaoo/969d337a6c46780d5484896d6117b655 to your computer and use it in GitHub Desktop.
Create random list of variable length
and print common unique elements from
both the lists in single line of code.
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
# Generate two random lists for different lengths | |
# 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. | |
import random | |
test1 = int(input("Enter the length of the first array: ")) | |
test2 = int(input("Enter the length of the second array: ")) | |
a = [random.randint(0, 100) for i in range(test1)] | |
b = [random.randint(0, 100) for i in range(test2)] | |
print(a, b) | |
c = print([i for i in a if i in b]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment