[Python] Finding a subset of values in another list

Discussão em 'Python' iniciado por Stack, Janeiro 31, 2025.

  1. Stack

    Stack Membro Participativo

    Why does this always print false?

    I expected a different outcome because the first two items in the 4th element in List1 are 61, 64 and those match 2 items in the 1st element of List2 which has 61, 62, 64, 70

    List1 = [
    [60, 64, 67],
    [62, 67, 72],
    [62, 66, 69],
    [61, 64, 69],
    [64, 66, 71],
    [63, 66, 71],
    ]

    List2 = [
    [61, 62, 64, 70],
    [60, 61, 62, 63],
    [64, 65, 67, 69],
    [65, 70, 66, 61],
    ]

    for x in List1:
    is_subset = all([(y in List2) for y in x[0:2]])
    print(is_subset)

    Continue reading...

Compartilhe esta Página