title: Which is the most pythonic way to check if the current method has been executed in a specific method?
body: <p>I am using Python 3 and I am trying to check if the current method has been called from a specific method. This one has not to be necessarily the parent call, only one of the ancestors.</p>
  <blockquote>
  <p>Example:</p>
  <p>I need to know if the method <strong>F</strong> is called from the method
  <strong>C</strong>. The method <strong>A</strong> calls <strong>B</strong>, <strong>B</strong> calls <strong>C</strong>, <strong>C</strong> calls <strong>D</strong>, <strong>D</strong> calls <strong>E</strong>, <strong>E</strong> calls <strong>F</strong>. So the ancestor methods of <strong>F</strong> are <strong>[A, B, C, D, E]</strong>. Since <strong>C</strong> is in this list, my
  method returns <code>True</code>, otherwise returns <code>False</code>.</p>
  </blockquote>
  <p>I have two solutions (I will replace the method names with parameters):</p>
  <p>First one, which I think is faster:</p>
  <pre><code>for frame in inspect.stack():
      if frame.function == 'C':
          return True
  </code></pre>
  <p>Second one:</p>
  <pre><code>methods = [frame.function for frame in inspect.stack()]
  if 'C' in methods:
      return True
  </code></pre>
  <p>Is the first solution better? Any suggestion to improve it? Is this already made in any library?</p>