taschini / pyinterval

PyInterval — Interval arithmetic in Python
http://pyinterval.readthedocs.io
Other
83 stars 25 forks source link

Filter out zero-length components #14

Open kenahoo opened 7 years ago

kenahoo commented 7 years ago

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
taschini commented 7 years ago

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])