Is there a better way to code this?
def __contains__(self, e):
return e in self.segments or True in [e in x for x in self.segments]
This function should return true if e is in self.segments or if e is in any of the segments in self.segments.
I’m still trying to learn how to use the [a for a in b if c] notations and I’m hoping that someone one StackOverflow can help me simplify that snippet.
anystops on the first element that evaluates toTrueand, without the square brackets, Python does not create an intermediary list.Read about Generator Expressions vs. List Comprehension