Can lambda be used instead of a method, as a key in sorted()?
<p>This is my first time asking a question. I've already got so much help from you without even asking. (Gratitude face).
So, I found this useful piece of code from around here a few weeks ago.</p>

<pre><code>import re

def yearly_sort(value):
    numbers = re.compile(r'(\d+)')
    parts = numbers.split(value)
    parts[1::2] = map(int, parts[1::2])
    return parts
</code></pre>

<p>It works perfectly here:</p>

<pre><code>def get_files_sorted(path_to_dir):
   file_names = []
   for root, dirs, files in os.walk(path_to_dir):
      for file_name in sorted(files, key=yearly_sort):
         file_names.append(os.path.join(root, file_name))
   return file_names
</code></pre>

<p>Now, I'm facing a problem describing the above function (as you can already see from a non-descriptive method name).</p>

<p>What should be the name of above method (instead of some_sort())?</p>

<p>Can this method be squeezed somehow in a lambda such that <strong>key</strong> in the sorted() can bind to key=lambda?</p>

<p>It definitely can be <code>lambda</code> function. For example look at that <a href="http://stackoverflow.com/questions/3766633/how-to-sort-with-lambda-in-python">question</a>.</p>

<p>But if you have complex function you should never move it to <code>lambda</code> because readability significantly decreases.</p>

<p>So here is <a href="https://www.python.org/dev/peps/pep-0020/" rel="nofollow">Zen of Python</a></p>

<blockquote>
  <p>Complex is better than complicated.</p>
</blockquote>

python python-3.x lambda