[CentralOH] Python Puzzler -- The little max bug
Eric Floehr
eric at intellovations.com
Wed Mar 11 00:42:07 CET 2015
One clarification, in the parse_* functions, "f" should be "lines" but it
doesn't really matter for this puzzle.
On Tue, Mar 10, 2015 at 7:38 PM, Eric Floehr <eric at intellovations.com>
wrote:
> The following code has a bug.
>
> The code takes input and generates a dictionary of dictionaries of
> dictionaries of the following form:
>
> {
> 'hour1':
> { 'formula_type1': { ... },
> 'formula_type2': { ... },
> ...
> },
> 'hour2':
> { 'formula_type1': { ... },
> 'formula_type2': { ... },
> ...
> },
> ...
> }
>
> 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.
>
> What was the bug, and why was MAXT the only formula type affected?
>
>
> ##########################################
>
> hoursdict = {}
>
> for line in lines:
> formula_type = ### Code to determine formula_type ###
> hour = ### Code to determine hour ###
>
> try:
> hourdict = hoursdict[hour]
> except:
> hourdict = {}
> hoursdict[hour] = {}
>
> hourdict[formula_type] = {}
>
> if formula_type in ('MAXT','MINT'):
> parse_h1h4_formulas(f, hourdict[formula_type])
> elif formula_type == 'CLOUD':
> parse_cloud_formulas(f, hourdict[formula_type])
> elif formula_type == 'PRECIP':
> parse_precip_formulas(f, hourdict[formula_type])
>
> return hoursdict
>
> ##########################################
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20150310/5e19979e/attachment.html>
More information about the CentralOH
mailing list