[Python] How to check if a list contains all the elements of another list INCLUDING duplicates

Discussão em 'Python' iniciado por Stack, Maio 28, 2025.

  1. Stack

    Stack Membro Participativo

    e.g.

    t = ["A", "A", "A", "b", "b"]
    s = ["A", "A", "b", "b"]


    s does not contain every element in t. t contains every element in s.

    I came up with this but wonder if there is a more efficient way

    def check(l1, l2):
    for i in l2:
    if(l2.count(i) > l1.count(i)):
    return False
    return True

    Continue reading...

Compartilhe esta Página