On Fri, Mar 11, 2016 at 10:24 AM, Gregory Ewing <greg.ew...@canterbury.ac.nz> wrote: > Instead, pull them out and give them meaningful names. > Doing so with the above code gives: > > name = m.group(1) > value = m.group(2) > if name not in od.keys(): > od[name] = int(value) > else: > od[name] += int(od.get(name, 0)) > > Now it's a lot eaier to see that you haven't used the > value anywhere in the second case, which should alert > you that something isn't right.
Although in this case, the code is majorly redundant - and could be replaced entirely with a defaultdict(int). ChrisA -- https://mail.python.org/mailman/listinfo/python-list