Suppose we have the following set: Sand the value v:
S = {(0,1),(2,3),(4,5)}
v = 3
I want to check if the vsecond element is any of the pairs within the set. My current approach:
for _, y in S:
if y == v:
return True
return False
I don’t really like this, because I have to add it to a separate function, and something tells me that maybe this is the best way to do this. Can anyone shed some light?
source
share