mercredi 8 avril 2020

Comparing lists, except for certain characters [closed]

I have made 8 lists in python and sorted a deck of cards in between them. For example:

  • A[k3], which is 3 of knights

    If the list does not contain any cards it is set to '--'

I am trying to compare these lists A, B, C, D, E, F, G, H to check if any of them have the same value, example:

  • A[k3] and C[s3].

What I have done so far is this mess:

if (A[-1] != B[-1] and A[-1] != C[-1] and A[-1] != D[-1] and A[-1] != E[-1] and A[-1] != F[-1] and A[-1] != G[-1] and A[-1] != H[-1] and
    B[-1] != A[-1] and B[-1] != C[-1] and B[-1] != D[-1] and B[-1] != E[-1] and B[-1] != F[-1] and B[-1] != G[-1] and B[-1] != H[-1] and
    C[-1] != A[-1] and C[-1] != B[-1] and C[-1] != D[-1] and C[-1] != E[-1] and C[-1] != F[-1] and C[-1] != G[-1] and C[-1] != H[-1] and
    D[-1] != A[-1] and D[-1] != B[-1] and D[-1] != C[-1] and D[-1] != E[-1] and D[-1] != F[-1] and D[-1] != G[-1] and D[-1] != H[-1] and
    E[-1] != A[-1] and E[-1] != B[-1] and E[-1] != C[-1] and E[-1] != D[-1] and E[-1] != F[-1] and E[-1] != G[-1] and E[-1] != H[-1] and
    F[-1] != A[-1] and F[-1] != B[-1] and F[-1] != C[-1] and F[-1] != D[-1] and F[-1] != E[-1] and F[-1] != G[-1] and F[-1] != H[-1] and
    G[-1] != A[-1] and G[-1] != B[-1] and G[-1] != C[-1] and G[-1] != D[-1] and G[-1] != E[-1] and G[-1] != F[-1] and G[-1] != H[-1] and
    H[-1] != A[-1] and H[-1] != B[-1] and H[-1] != C[-1] and H[-1] != D[-1] and H[-1] != Em[-1] and H[-1] != F[-1] and H[-1] != G[-1]):

This has worked so far, but I now want to not compare two lists if they are empty. This code does not do this as when the list is empty, or contains just '--' the last element in both lists has the potential to be the same.

Is there any way of doing this in python?

Aucun commentaire:

Enregistrer un commentaire