Answers for "intersection of two arrays python"

8

intersection of two lists python

>>> a = [1,2,3,4,5]
>>> b = [1,3,5,6]
>>> list(set(a) & set(b))
[1, 3, 5]
Posted by: Guest on August-10-2020
3

intersection in list

def intersection(lst1, lst2): 
    lst3 = [value for value in lst1 if value in lst2] 
    return lst3 
  
# Driver Code 
lst1 = [4, 9, 1, 17, 11, 26, 28, 54, 69] 
lst2 = [9, 9, 74, 21, 45, 11, 63, 28, 26] 
print(intersection(lst1, lst2))
Posted by: Guest on May-09-2020
1

intersection of lists in python

import numpy as np
recent_coding_books =  np.intersect1d(recent_books,coding_books)
Posted by: Guest on June-08-2020
0

intersection of 3 array in O(n) python

def intersection(A, B, C):
    '''
    Intersection of 3 array in O(n).
    '''
    i = j = k = 0
    len1 = len(A)
    len2 = len(B)
    len3 = len(C)
	
    while (i < len1 and j < len2 and k< len3):
        
        if (A[i] == B[j] and B[j] == C[k]):
            print(A[i])
            i += 1
            j += 1
            k += 1
        elif A[i] < B[j]:
            i += 1
        elif B[j] < C[k]:
            j += 1
        else:
            k += 1
Posted by: Guest on September-08-2021

Code answers related to "intersection of two arrays python"

Python Answers by Framework

Browse Popular Code Answers by Language