Skip to content

Instantly share code, notes, and snippets.

@prologic
Created June 21, 2015 22:04
Show Gist options
  • Save prologic/ec2ed327030d445bfe92 to your computer and use it in GitHub Desktop.
Save prologic/ec2ed327030d445bfe92 to your computer and use it in GitHub Desktop.
created by github.com/tr3buchet/gister
from itertools import chain, ifilter, imap # noqa
def flatten(*seq):
return chain(*(chain.from_iterable(x) for x in seq))
def within(x, y):
def f(i):
return x <= i <= y
return f
a = [[0.8, 0.9, 1.], [0.5, 2.6, 2.2], [1.5, 5.6], [5.8, 2.3, 1.9], ]
b = [[6.5, 3.9, 7.5], [2.5, 4.6, 8.8], [1, 2, 5], ]
@prologic
Copy link
Author

Example:

>>> list(imap(within(0.1, 2.5), flatten(a, b)))
[True, True, True, True, False, True, True, False, False, True, True, False, False, False, True, False, False, True, True, False]
>>> list(ifilter(within(0.1, 2.5), flatten(a, b)))
[0.8, 0.9, 1.0, 0.5, 2.2, 1.5, 2.3, 1.9, 2.5, 1, 2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment