forked from jadid800/love_babbar_450_dsa_questions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_union_and_interset.py
41 lines (32 loc) · 1.15 KB
/
6_union_and_interset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import numpy as np
class Array_operation:
def __init__(self, array1, array2):
self.array1=array1
self.array2=array2
def union(self):
union_arr=self.__copy_element(array1)
for i in array2:
if(not self.__isin(array1,i) and not self.__isin(union_arr,i)):
union_arr.append(i)
return np.array(union_arr)
def interset(self):
intetset_arr=[]
for i in array1:
if(self.__isin(array2, i) and not self.__isin(intetset_arr,i)):
intetset_arr.append(i)
return np.array(intetset_arr)
def __copy_element(self, copy_from):
copy_to=[]
for i in copy_from:
copy_to.append(i)
return copy_to
def __isin(self,array,target):
for i in array:
if(i==target):
return True
return False
array1=np.array(list(map(int, input().split())))
array2=np.array(list(map(int, input().split())))
array_operation=Array_operation(array1,array2)
print("union array: ",array_operation.union())
print("interset array: ", array_operation.interset())