Find corresponding value with maximum in a list of lists
<p>I have a list (created from a .csv file) with an output like this: </p>

<p><code>[('25.09.2016 01:00:00', 'MQ100D1_3_1_4', '225'), 
('25.09.2016 02:00:00', 'MQ100D1_3_1_4', '173'), 
('25.09.2016 03:00:00', 'MQ100D1_3_1_4', '106'), 
('25.09.2016 04:00:00', 'MQ100D1_3_1_4', '74'), 
('25.09.2016 05:00:00', 'MQ100D1_3_1_4', '84'), 
('25.09.2016 06:00:00', 'MQ100D1_3_1_4', '122'), 
('25.09.2016 07:00:00', 'MQ100D1_3_1_4', '110'), 
('25.09.2016 08:00:00', 'MQ100D1_3_1_4', '177'), 
('25.09.2016 09:00:00', 'MQ100D1_3_1_4', '301'), 
('25.09.2016 10:00:00', 'MQ100D1_3_1_4', '552'), 
('25.09.2016 11:00:00', 'MQ100D1_3_1_4', '812'), 
('25.09.2016 12:00:00', 'MQ100D1_3_1_4', '922'), 
('25.09.2016 13:00:00', 'MQ100D1_3_1_4', '970'), 
('25.09.2016 14:00:00', 'MQ100D1_3_1_4', '1264'), 
('25.09.2016 15:00:00', 'MQ100D1_3_1_4', '1338'), 
('25.09.2016 16:00:00', 'MQ100D1_3_1_4', '1347'), 
('25.09.2016 17:00:00', 'MQ100D1_3_1_4', '1491'), 
('25.09.2016 18:00:00', 'MQ100D1_3_1_4', '1637'), 
('25.09.2016 19:00:00', 'MQ100D1_3_1_4', '1544'),
('25.09.2016 20:00:00', 'MQ100D1_3_1_4', '974'),
('25.09.2016 21:00:00', 'MQ100D1_3_1_4', '503'), 
('25.09.2016 22:00:00', 'MQ100D1_3_1_4', '359'), 
('25.09.2016 23:00:00', 'MQ100D1_3_1_4', '218'), 
('25.09.2016 23:59:59', 'MQ100D1_3_1_4', '132')......</code></p>

<p>The first element is the time value. The second is the measuring point. The third the amount of cars measured in that time interval.</p>

<p>There are 536 items in total.</p>

<p>For my program, I need the maximum of the third element in chunks of 12 (before noon, after noon). </p>

<p>For the maximum I've written the code:</p>

<p><code>i = 0
topHour = []
for i in range(0, len(finalList), 12):
    values = max([int(i[-1]) for i in finalList[i:i+12]])
    topHour.append(values)</code></p>

<p>This provides me with an output like this:</p>

<pre><code>[922, 1637, ...]
</code></pre>

<p>However, how do I get the corresponding time value (first element) with it? In this very example the program should output <code>'25.09.2016 12:00:00'</code> and <code>'25.09.2016 18:00:00'</code> together with the maximum.</p>

<p>use the lambda function is appropriate, you can do it like:</p>

<pre><code>max(finalList[i:i+12]], key=lambda x: int(x[-1]))
</code></pre>

<p>then you can process the triple further...</p>

<p>btw, in your code, the <code>i</code> is ambiguous, you should take care.</p>

python list python-3.x