Working of Enumerate in Python
<p>I'm new to Python and I'm currently solving questions to improve my coding skills. I came across the question where I to find the maximum value in a <code>List</code> and it's corresponding value in an other <code>List</code> with the same <code>index</code> number of the maximum value. </p>

<p>for example:
I have two <code>Lists</code> with values  <code>L1 = [9, 12, 9 ,6]</code> and <code>L2 = [2, 3, 4, 5]</code>
I have to find the maximum value in the <code>List L1</code> and the index of the maximum value should be used in <code>List L2</code> to find it's corresponding value. </p>

<pre><code>Max value in List L1 - 12
Index of the max value - 1
print L2[1] -&gt; 3
</code></pre>

<p>So to achieve the above logic, I have re-searched a way and obtained it. But I'm not able to understand how the logic is working. </p>

<pre><code>import operator   
index, value = max(enumerate(l1), key=operator.itemgetter(1))
print value, 
print l2[index]
</code></pre>

<p>OUTPUT: <code>12 3</code></p>

<p>To understand how the above function is working, I tried to print each section separately but still not able to understand how the logic is working.</p>

<pre><code>print l1 - [9, 12, 9 , 6]
print l2 - [2, 3, 4, 5]
print list(enumerate(l1)) - [&lt;0, 9&gt;, &lt;1, 12&gt;, &lt;2, 9&gt;, &lt;3, 6&gt;]
print list(enumerate(l2)) - [&lt;0, 2&gt;, &lt;1, 3&gt;, &lt;2, 4&gt;, &lt;3, 5&gt;]
print max(enumerate(l1)) - &lt;3, 6&gt;
print max(enumerate(l2)) - &lt;3, 5&gt;
</code></pre>

<p>Please help me in understanding how the <code>enumerate</code> function and <code>key=operator.itemgetter(1))[0]</code>is working in the above logic. Thanks in advance. Your help is much appreciated. </p>