0

I have type of object called "GenomicLocation". I want to support the operation "in" for that object, so that I can write

genomic_location1 in genomic_location2

if certain conditions are met.

Is this possible? If so, how do I do it?

The Unfun Cat
  • 29,987
  • 31
  • 114
  • 156

1 Answers1

4

You should define the method

__contains__

Example:

>>> class Thing(object):
...     def __contains__(self, x):
...         return x == 'potato'
...     
>>> t = Thing()
>>> 'potato' in t
True
>>> 'spam' in t
False
wim
  • 338,267
  • 99
  • 616
  • 750