“bukan persimpangan dua daftar python” Kode Jawaban

persimpangan dua daftar python

>>> a = [1,2,3,4,5]
>>> b = [1,3,5,6]
>>> list(set(a) & set(b))
[1, 3, 5]
batman_on_leave

persimpangan python dari dua daftar

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)) 
Victorious Vendace

bukan persimpangan dua daftar python

set(a) ^ set(b)
{2, 4, 6}
Bloody Buffalo

Python Temukan persimpangan dua daftar

# 3 Approaches to find intersect of two lists:
# set two lists:
a = [1,2,3,4,5,6,7,8]
b = [8,7,4,3,100,200]
# the intersect c should be [3,4,7,8]
# Method 1:
c = list(set(a) & set(b))
print(c)
# Method 2:
c = list(filter(set(a).__contains__, b))
print(c)
# Method 3:
c = list(set(a).intersection(b))
Dead Dragonfly

persimpangan dua daftar python

# Python program to illustrate the intersection
# of two lists in most simple way
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))
Africodes

Python Dapatkan persimpangan dua daftar

# intersection of two lists (lst1 & lst2)
In [1]: x = ["a", "b", "c", "d", "e"]

In [2]: y = ["f", "g", "h", "c", "d"]

In [3]: set(x).intersection(y)
Out[3]: {'c', 'd'}
# has_intersection = bool(set(x).intersection(y)) -> True
gdfelt

Jawaban yang mirip dengan “bukan persimpangan dua daftar python”

Pertanyaan yang mirip dengan “bukan persimpangan dua daftar python”

Lebih banyak jawaban terkait untuk “bukan persimpangan dua daftar python” di TypeScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya