title: optimize 'for loop' with lambda in python
body: <p>I am using regex for finding the pattern in two different columns(<code>Description and Labels</code>) from two different dataframe(<code>Input data</code> and <code>Mapping data</code>) and if the pattern matches then map the <code>Labels</code> from <code>Mapping data</code> with <code>Input Data</code>. </p>
  
  <pre><code>def func2(x,pattern,labels):
      """
      # Searching pattern in Input Data and returning the matched Description
      #
      #Input Parameter
      # 1) x             : Description column of Input Data 
      # 2) pattern       : Pattern column of Mapping Data
      # 3) Labels        : Labels column of Mapping Data
      """
      for p,d in zip(pattern, labels):
          if re.search(r'\b'+ p +r'\b',x):
              return d
      for p,d in zip(pattern, labels):
          if re.search(p,x):
              return d
  </code></pre>
  
  <p>This code is working perfectly fine, but as my data is hug, its taking much time.Is there any otherway to replace this <code>for loop</code> with <code>Lambda</code> function</p>