Have you observed this happening (i.e., the label having both)? If not, it seems like it might be a bottleneck since you'd potentially run the check millions or tens of millions of times. Could it just be ``if forward_id in label: ... elif reverse_id in label: ... else: ...``