Convert list to nested lists and dicts
<p>I have a set of data that looks similar to this:</p>

<pre><code>[  {"name":"item.key" , "value":"value"},
   {"name":"item.key2" , "value":"value2"},
   {"name":"item.list.0" , "value":"listValue1"},
   {"name":"item.list.1" , "value":"listValue2"},
   {"name":"item.list.2" , "value":"listValue3"},·
   {"name":"item.list2.0.key1" , "value":"list2Key1Value"},
   {"name":"item.list2.0.key2" , "value":"list2Key2Value"},
   {"name":"item.list2.0.key3" , "value":"list2Key3Value"},·
   {"name":"item.list3.0.key1" , "value":"list3Key1Value"},
   {"name":"item.list3.0.key2" , "value":"list3Key2Value"},
   {"name":"item.list3.0.key3" , "value":"list3Key3Value"},
   {"name":"other.key" , "value":"otherKeyValue"}
]
</code></pre>

<p>The names were flattened from nested data containing lists and dicts.  I now want to unflatten it back into dicts and lists (where appropriate).</p>

<p>So far I have this:</p>

<pre><code>obj = {}
def addObj(o, path, value):
    if len(path) &gt; 1:
        o = o.setdefault(path.pop(0), {})
        addObj(o, path, value)
    else:
        o[path.pop(0)] = value

for item in data:
    parts = item['name'].split(".")
    addObj(obj, parts, item['value'])
</code></pre>

<p>Which will generate this:</p>

<pre><code>{'item': {
     'key': 'value',
     'key2': 'value2',
     'list': {
         '0': 'listValue1',
         '1': 'listValue2',
         '2': 'listValue3'},
     'list2': {
         '0': {
             'key1': 'list2Key1Value',
             'key2': 'list2Key2Value',
             'key3': 'list2Key3Value'}
     },
     'list3': {
         '0': {
             'key1': 'list3Key1Value',
             'key2': 'list3Key2Value',
             'key3': 'list3Key3Value'}
     }
 },
 'other': {'key': 'otherKeyValue'}
}
</code></pre>

<p>But now, I want any dict that has keys that can all be cast as ints to be converted to lists, so my final output would look more like:</p>

<pre><code>{'item': {
     'key': 'value',
     'key2': 'value2',
     'list': [
         'listValue1',
         'listValue2',
         'listValue3'],
     'list2': [{'key1': 'list2Key1Value',
             'key2': 'list2Key2Value',
             'key3': 'list2Key3Value'}],
     'list3': [{'key1': 'list3Key1Value',
             'key2': 'list3Key2Value',
             'key3': 'list3Key3Value'}]
 },
 'other': {'key': 'otherKeyValue'}
}
</code></pre>

<p>Any suggestions on how I can accomplish this? </p>
