pyinterval icon indicating copy to clipboard operation
pyinterval copied to clipboard

Filter out zero-length components

Open kenahoo opened this issue 7 years ago • 1 comments

I'm using the pyinterval package to represent unions of open intervals. Thus I would like to have an easy way to get rid of components whose inf and sup are identical. Is there a more elegant way to do it than the following?

        b = interval()
        for i in a:
            if i.sup > i.inf:
                b |= i
        a = b

kenahoo avatar Mar 01 '17 23:03 kenahoo

The following should do the trick:

>>> x = interval([1, 3], [4])
>>> interval.new(c for c in x if c.inf < c.sup)
interval([1.0, 3.0])

taschini avatar Mar 05 '17 17:03 taschini