擅长:python、mysql、java
<pre><code>def recombine(k, substring):
newd = dict()
newk = dict()
key = [i for i in k if (substring in i)] # select out the strings which contains substring
value = [k[i] for i in key] # select out the corresponding value of target key
for i in value:
for j in i.items():
newk[j[0]] = j[1]
newd[substring] = newk
return newd
k = { "item" : { "foo" : "bar", "fizz" : "buzz"},
"itemSuper" : { "boo" : "far", "bizz" : "fuzz"},
"itemDuper" : { "omg" : "wtf", "rofl" : "lmao"}}
recombine(k, 'item')
</code></pre>
<p>输出</p>
<pre><code>{'item': {'foo': 'bar',
'fizz': 'buzz',
'boo': 'far',
'bizz': 'fuzz',
'omg': 'wtf',
'rofl': 'lmao'}}
</code></pre>