Find the Union and Intersection of the two sorted arrays in Python
One Subscription, For Everything
The new cool way of learning and upskilling -
One Subscription access everything
Get Access to PrepInsta Prime
from FAANG/IITs/TOP MNC's
PrepInstaPrime
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.
Login/Signup to comment
a=[1,2,3,4,5]
b=[4,5,6,7,8]
intersection1=[]
union1=a[:]
for i in b:
if i not in a:
union1.append(i)
if i in a:
intersection1.append(i)
print(intersection1)
print(union1)