title: Can I call a function inside a Lambda expression in python
body: <p>I have a function with including if, else condition and for loop. I want to write this function inside a lambda expression. I tried from many ways to create this lambda function. But still I couldn't do it. This is my function with another rules.</p>
  
  <pre><code>negation ='no,not,never'.split(',')
  list2 = 'miss,loss,gone,give up,lost'.split(',')
  
  def f(sentence):
    s = sentence.split()
    l = [s.index(word) for word in s if word in list2]
  # Will returns list of indices (of sentence) where word is in list2
     if len(l) &gt; 0:
      for e in l:
          # Check previous word
          if s[e-1] not in negation:
              print 'sad'
  </code></pre>
  
  <p>Can I express this function inside a lambda expression since I developing a rule based classifier for detect emotion from a sentence like happy, sad, angry. Following is my lambda function.</p>
  
  <pre><code>rules = [(lambda x: word_tokenize(x)[-1] == '?', "neutral"),
           (lambda x: word_tokenize(x)[0] in question, "neutral"),
           (lambda x: any(word in list2 for word in [WordNetLemmatizer().lemmatize(word,'v') for word in word_tokenize(x)]), "sad"),
       (lambda x: any(word in list1 for word in [WordNetLemmatizer().lemmatize(word,'v') for word in word_tokenize(x)]), "happy")]
  
           print classify("I miss you", rules)
  </code></pre>