title: Efficient filter, map, and reduce operation on a long list in Python
body: <p>There is a list (price_list) of 10 million numbers as a price in range (0-100). I would like to do the following operations consequently:</p>
  <ol>
  <li>Filter the list with this condition (list_item &lt; 30)</li>
  <li>Multiply each list_item with a fixed number (mapping)</li>
  <li>compute the sum of all elements (reduce)</li>
  </ol>
  <p>Here is the sample code:</p>
  <blockquote>
  <pre><code>import time
  import numpy as np
  from functools import reduce
  
  with open('price_list.txt') as f:
      price_list = f.read().split('\n')
      
  price_list = np.array(price_list).astype(int)  # convert string to int
  </code></pre>
  </blockquote>
  <p>I tried following options:</p>
  <ul>
  <li><p>Using NumPy module (0.1069948673248291 seconds): <code>total =  np.sum(price_list[price_list &lt; 30] * 1.05)</code></p>
  </li>
  <li><p>Using brute force loop (9.485718965530396 seconds)</p>
  </li>
  <li><p>Using filter, map, and reduce functions (10.078220844268799 seconds): <code>total =  reduce(lambda x,y: x+y,map(lambda x: x * 1.05, filter(lambda x: x &lt; 30, price_list)) )</code></p>
  </li>
  <li><p>Using list comprehension (8.609008073806763 seconds): <code>total= sum([x * 1.05 for x in price_list if x &lt;30])</code></p>
  </li>
  <li><p>Using generator (8.780538320541382 seconds): <code>total= sum((x * 1.05 for x in price_list if x &lt;30))</code></p>
  </li>
  </ul>
  <p>It is obvious that the NumPy module is significantly fast in these operations. Is there any alternative solution for running this code faster using Python built-in functions and capabilities?</p>