Python: Locate 3 adjacent list items and determine list index of first of them
<p>I need to process weather station data which is in a format like this (SYNOP), where each line represents one measurement and I have thousands of measurements:</p>

<pre><code>line = 'AAXX 01004 60265 32970 03404 10048 20010 38997 48605 51014='
</code></pre>

<p>Starting with the 6th block, the blocks are numbered (1xxxx 2xxxx 3xxxx etc, sometimes only 5 blocks but sometimes also more with additional data)</p>

<p>The crucial point is that <em>the number of blocks between the AAXX and the 1xxxx block is not always the same</em>, but I know that 2 blocks before the 1xxxx block there is data I need. To reliably pinpoint that block I would need to determine the position of the 1xxxx block and count backwards from there.</p>

<p>My idea is to split the line along spaces into a list, and then iterate through the list items to find the position in the list of the 1xxxx block.</p>

<pre><code>list = line.split(' ')
</code></pre>

<p>But I don't know how to do this iteration. There must be a reasonably elegant way to look for 3 blocks where the first starts with 1, the second with 2, and the third with 3, then return the list index of the first block?</p>

<p>This may be very simple but I'm unable to figure it out, and would be grateful for any tips!</p>

<p>EDIT: To clarify, it's possible that another block starting with 1 appears before the one I need, so the only reliable way to pinpoint the block I need is to ensure that it is followed by one that starts with 2 and another that starts with 3 (that should reduce the chance of a false positive to pretty much 0).</p>
