problème verification tout les element d'une liste existe dans une autre
salut,
Code:
1 2 3 4
| check = all(item in all_migratory for item in solutionforpriority)
if check:
print("yes the MT towoard target solution ", solutionforpriority, " has all item of allMT",
all_migratory) |
pour solutionforpriority[4] et all_migratory:[9], [17], [4]
resultat:
yes the MT towoard target solution [4] has all item of allMT [[9], [17], [4]]
resultat erroné
je peux utiliser subset pour verifier ça
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
def aplatliste(L):
"""transforme un arbre (liste de listes...) en une liste à 1 seul niveau
"""
R = []
for elem in L:
if isinstance(elem, (list, tuple)):
R.extend(aplatliste(elem))
else:
R.append(elem)
return R
check=set(L1).issuperset(set(aplatliste(L2))) |
L1=[12, 12, 12, 11, 11]
L2= [[12], [11]]