Reputation: 1
planta_accesibles = probpl.RelacionRigida(
lambda a1, p1, p2: (a1,(p1,p2))
in [('A0', ('0', '1', '2', '3', '4'))]
)
I want to search if p1 and p2 are included in my list 'A0', but python compare tuple "p1,p2" with tuple '0,1'. If I hold on " '2', '3', '4' " I don´t take a correct reponse.
Sorry for my english.
Upvotes: 0
Views: 84
Reputation: 11075
I don't know what probpl.RelaciónRígida()
is so I can't know what that needs, but I think I can sort of recognize what you're trying to do with the lambda function (feel free to correct me or ask questions).
It looks like you want to have a list named 'A0'
and test if p1
and p2
are contained in it. In this case, I believe a dictionary would suit your needs better than a nested tuple:
ref = {"A0": ("0", "1", "2", "3", "4")}
This allows you to test the dictionary to determine if it contains a value (your tuple) associated with the key a1
:
a1 in ref
After determining the dictionary contains an entry for a1
, you can test whether that entry contains p1
and p2
:
(p1 in ref[a1]) and (p2 in ref[a1]) #parenthesis are only added for readability
If I were to add this to your existing example it would look something like:
ref = {"A0": ("0", "1", "2", "3", "4")}
test = lambda a1, p1,p2: (a1 in ref) and (p1 in ref[a1]) and (p2 in ref[a1])
planta_accesibles = probpl.RelaciónRígida(test)
Upvotes: 1