<div dir="ltr"><div>The following code has a bug. <br><br></div><div>The code takes input and generates a dictionary of dictionaries of dictionaries of the following form:<br><span style="font-family:monospace,monospace"></span><br><span style="font-family:monospace,monospace">{<br>  'hour1':<br></span></div><div><span style="font-family:monospace,monospace">    { 'formula_type1': { ... },<br></span></div><div><span style="font-family:monospace,monospace">      'formula_type2': { ... },<br>       ...<br>    },<br></span></div><div><span style="font-family:monospace,monospace">  'hour2':<br></span></div><div><div><span style="font-family:monospace,monospace">    { 'formula_type1': { ... },<br></span></div><div><span style="font-family:monospace,monospace">      'formula_type2': { ... },<br>       ...<br>    },<br>   ...<br></span></div><span style="font-family:monospace,monospace">}<br></span></div><div><br>The symptoms were that formula types MINT, CLOUD, and PRECIP were showing up in the final dictionary (hoursdict), but MAXT was not. For any set of lines and hour all the formula types showed up exactly once.<br><br>What was the bug, and why was MAXT the only formula type affected?<br><br><br><span style="font-family:monospace,monospace">##########################################<br><br></span><span style="font-family:monospace,monospace"><span style="font-family:monospace,monospace">hoursdict = {}<br></span><br>for line in lines:<br></span></div><span style="font-family:monospace,monospace">   formula_type = ### Code to determine formula_type ###<br></span><div><span style="font-family:monospace,monospace">   hour = ### Code to determine hour ###<br><br></span></div><div><span style="font-family:monospace,monospace">    try:<br>        hourdict = hoursdict[hour]<br>    except:<br>        hourdict = {}<br>        hoursdict[hour] = {}<br>                <br>    hourdict[formula_type] = {}<br>                <br>    if formula_type in ('MAXT','MINT'):<br>        parse_h1h4_formulas(f, hourdict[formula_type])<br>    elif formula_type == 'CLOUD':<br>        parse_cloud_formulas(f, hourdict[formula_type])<br>    elif formula_type == 'PRECIP':<br>        parse_precip_formulas(f, hourdict[formula_type])<br><br></span></div><div><span style="font-family:monospace,monospace">return hoursdict<br><br></span></div><div><span style="font-family:monospace,monospace">##########################################<br></span><br></div></div>