Created
July 30, 2017 13:35
-
-
Save rostyq/fcaf99df7aed2d3dd60f8d93894fa45d to your computer and use it in GitHub Desktop.
Exercise on www.practicepython.org
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
import numpy | |
def rnd_list(): | |
size_of_list = numpy.random.randint(10, 20) | |
return numpy.random.randint(0, 100, size_of_list) | |
def rm_duplicates_1(lst): | |
return list(set(lst)) | |
def rm_duplicates_2(lst): | |
new = list() | |
for i in lst: | |
if i not in new: | |
new.append(i) | |
return new | |
def intersection(list1, list2): | |
list1, list2 = rm_duplicates_1(list1), rm_duplicates_1(list2) | |
list_intersection = [i for i in list1 if i in list2] | |
return list_intersection | |
a, b = rnd_list(), rnd_list() | |
print(str(a)+'\n'+str(b)+'\n') | |
print(rm_duplicates_1(a)) | |
print(rm_duplicates_2(a)) | |
print(intersection(a, b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment