need help optimizing a geo algorithm using a map() operation, lists, floats and some validation
<p>Im doing som route(geo) calculations. 
I need to sort out some routes going in the "wrong" direction... 
all rides have "routes" and all routes consist of a lot of steps on the route.... each step has a lat. and a lng. pair. 
I hope this makes sense? </p>

<p>This is the way i do it now, and it works... however... im performing this operation on many(!) rides..routes...coordinate-pairs, so i could use a little speed-up in my code.  </p>

<pre><code>for ride in initial_rides:  
steps = ride.route.steps.all()  
    for step in steps:  
        if lat_min &lt; step.latitude&lt; lat_max and lng_min&lt; step.longitude&lt; lng_max:  
            approved_rides.append(ride)  
            break  
</code></pre>

<p>I better admit already that i'm no super programmer :) </p>

<p>i have tried construction something like this(without any luck):  </p>

<pre><code>for i in ride:  
    number  = sum(itertools.ifilter(lambda x: lat_min&lt; x.latitude&lt; lat_max and lng_min&lt; x.longitude&lt; lng_max, ride.route.steps.all()))  
    if number &gt;= 1:  
        approved_rides.append(ride)  
</code></pre>

<p>tried to combine lambda and ifilter however i get an error saying operator doesn't support types "int" and "step"... Am i doing something wrong?</p>

<p>should i be using list comprehensions?? map()?? or something else?</p>

<p>i have read through  <a href="http://www.python.org/doc/essays/list2str.html" rel="nofollow">http://www.python.org/doc/essays/list2str.html</a>   without any luck.</p>

<p>any help is greatly appreciated. thank you, and good day :)</p>

<p>Peter</p>
