Horje
check if a list contains any item from another list python Code Example
check if a list contains an item from another list python
## checking any elment of list_B in list_A
list_A = [1, 2, 3, 4]

list_B = [2, 3, 6]

check = any(item in list_A for item in list_B)

print(check)
# True
python check if list contains elements of another list
## checking all elements of list_B in list_A
list_A = [1, 2, 3, 4]
list_B = [2, 3]

check = all(item in list_A for item in list_B)

print(check)
# True
check if a list contains any item from another list python
## using set
list_A = [1, 2, 3, 4]
list_B = [2, 3]

set_A = set(list_A)
set_B = set(list_B)

print(set_A.intersection(set_B))

# True if there is any element same
# False if there is no element same
check if a list contains any item from another list python
## using set
list_A = [1, 2, 3, 4]
list_B = [5,1]

set_A = set(list_A)
set_B = set(list_B)

output = False if (set_A.intersection(set_B) == set()) else True
print(output)
# True if there is any element same
# False if there is no element same




Python

Related
pandas categorical to numeric Code Example pandas categorical to numeric Code Example
reportlab page size a4 Code Example reportlab page size a4 Code Example
pandas drop row from a list of value Code Example pandas drop row from a list of value Code Example
how to file in python Code Example how to file in python Code Example
df only take 2 columns Code Example df only take 2 columns Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7