Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out zero-length components #14

Open
kenahoo opened this issue Mar 1, 2017 · 1 comment
Open

Filter out zero-length components #14

kenahoo opened this issue Mar 1, 2017 · 1 comment

Comments

@kenahoo
Copy link

kenahoo commented Mar 1, 2017

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
Copy link
Owner

taschini commented Mar 5, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants