On Fri, Jan 3, 2014 at 11:07 AM, Chris Angelico <ros...@gmail.com> wrote: > On Sat, Jan 4, 2014 at 2:55 AM, Larry Martell <larry.mart...@gmail.com> wrote: >> The use case is that I'm parsing a XML file like this: >> >> <Parameter Name="DefaultVersion"> >> <Values> >> <Value> >> <Default>True</Default> >> </Value> >> </Values> >> <Values> >> <Value> >> <Current>False</Current> >> </Value> >> </Values> >> <Values> >> <Value> >> <Default>True</Default> >> <Current>False</Current> >> </Value> >> </Values> >> <Values> >> <Default>True</Default> >> </Values> >> >> This is an existing program that is putting the data into a dict. The >> dict keys are ['DefaultVersion','Default'] and >> ['DefaultVersion','Current']. These contain lists that have the >> True/False values. > > Are you assigning keys by value, or are you simply appending to the > lists? It looks to me like you could simply append another element to > both lists for each <Value> </Value> unit, with the given Default and > Current if available, or with None for any that aren't set. > Alternatively, when you get up to the <Value>, append None to each > list, and then when you see a value, assign to [-1] and overwrite the > None.
Your last suggestion is what I ended up doing, but I had to key off the <Values> </Values> unit - I couldn't use <Value> because that isn't present for ones that have no <Current> - that messed me up for hours. But it's working now. Thanks all! -- https://mail.python.org/mailman/listinfo/python-list