“Lista Python zawiera listę” Kod odpowiedzi

Sprawdź, czy część listy znajduje się na innej liście Python

'''    
    check if list1 contains any elements of list2
'''
result =  any(elem in list1  for elem in list2)
if result:
    print("Yes, list1 contains any elements of list2")    
else :
    print("No, list1 contains any elements of list2")
Fair Finch

Python Sprawdź, czy lista zawiera

# To check if a certain element is contained in a list use 'in'
bikes = ['trek', 'redline', 'giant']
'trek' in bikes
# Output:
# True
SkelliBoi

Lista Python zawiera listę

>>> items = set([-1, 0, 1, 2])
>>> set([1, 2]).issubset(items)
True
>>> set([1, 3]).issubset(items)
False
DreamCoder

Lista Python zawiera listę

#There's an all() and any() function to do this. To check if big contains ALL elements in small

result = all(elem in big for elem in small)
#To check if small contains ANY elements in big

result = any(elem in big for elem in small)
#the variable result would be boolean (TRUE/FALSE).
DreamCoder

Odpowiedzi podobne do “Lista Python zawiera listę”

Pytania podobne do “Lista Python zawiera listę”

Więcej pokrewnych odpowiedzi na “Lista Python zawiera listę” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu