You could do this with list comprehension I think:
thresholds = [0.11,0.12,0.125]
quotes = [[0.09,0.08,0.15],[0.09,0.08,0.15],[0.1,0.34,0.01]]
[filter(lambda x: x > thresholds[idx],qts) for idx,qts in enumerate(quotes)]
I made some real lists out of the given ones (omitting the ...
) such that this is an example that compiles.
The list comprehension works as follows: we iterate over the qts
from quotes
(and also obtain the corresponding index idx
, which is used to obtain the threshold). Next we perform a filter
operation on the qts
and only allow elements that are larger than the threshold[idx]
(the threshold for that timestamp).
Running this with python
gives:
$ python
Python 2.7.9 (default, Apr 2 2015, 15:33:21)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> thresholds = [0.11,0.12,0.125]
>>> quotes = [[0.09,0.08,0.15],[0.09,0.08,0.15],[0.1,0.34,0.01]]
>>> [filter(lambda x: x > thresholds[idx],qts) for idx,qts in enumerate(quotes)]
[[0.15], [0.15], [0.34]]
which seems to be what you want.
EDIT In python-3.x, this should work as well, although the filter is "delayed":
$ python3
Python 3.4.3 (default, Mar 26 2015, 22:03:40)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> thresholds = [0.11,0.12,0.125]
>>> quotes = [[0.09,0.08,0.15],[0.09,0.08,0.15],[0.1,0.34,0.01]]
>>> res=[filter(lambda x: x > thresholds[idx],qts) for idx,qts in enumerate(quotes)]
>>> res[0]
<filter object at 0x7f0d3fbc2be0>
>>> list(res[0])
[0.15]
If you want to materialize the lists straight away, you can slightly alter the list comprehension to:
[list(filter(lambda x: x > thresholds[idx],qts)) for idx,qts in enumerate(quotes)]
Which results in:
>>> [list(filter(lambda x: x > thresholds[idx],qts)) for idx,qts in enumerate(quotes)]
[[0.15], [0.15], [0.34]]