[SciPy-user] Conditionally adding items to a list

Roger Herikstad roger.herikstad@gmail....
Tue Aug 26 01:03:36 CDT 2008


Hi all,
 I have a prolem that I was wondering if anyone could come up with a
good solution for. I basically have to lists of number and I want to
add elements from one list to the other as long as the difference
between the added element and all elements already in that list
exceeds a certain threshold. The code I came up with is

map(times1.append,ifilter(lambda(x):
numpy.abs(x-numpy.array(times1)).min()>1000, times2))

but it quickly slows down if times2 becomes sufficiently long. I need
to be able to do this with lists of 100,000++ elements. Does anyone
know of a quicker way of doing this?

Thanks!

~ Roger


More information about the SciPy-user mailing list