title: How sorting deals with key and lambda functions in two given lists
body: <p>I'm new to programming and learning about the sort function. While I did search and looked at a number of SO articles regarding sort/lambda and some even very similar to my situation, I am still having a hard time grasping how exactly this code works. I also read the docs (<a href="https://docs.python.org/3/howto/sorting.html" rel="nofollow noreferrer">https://docs.python.org/3/howto/sorting.html</a>) and the examples there make sense to me but I can't seem to carry this knowledge onto this example here. Would someone be kind enough to help me with the code below? I understand this can be a duplicate but I am only asking because I don't have the knowledge base to get what I've read from other similar posts. Please help if you can, thanks. </p>
  
  <pre><code>a = [13, 15, 81, 4]
  b = [0, 1, 2, 3]
  b.sort(key = lambda x:a[x])
  b = [3, 0, 1, 2]
  </code></pre>
  
  <p>How does the order of list 'b' change from [0, 1, 2, 3] to [3, 0, 1, 2]? How does the list 'a' come into play?</p>