Re: How find all childrens values of a nested dictionary, fast!

2010-11-06 Thread Alexander Gattin
Hello, On Thu, Nov 04, 2010 at 09:20:04PM +, Arnaud Delobelle wrote: > Tough requirement, but I think I've got it. Two > lambdas, one reduce, one map ;) > > >>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]}, 'bc' > >>> :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,

Re: How find all childrens values of a nested dictionary, fast!

2010-11-05 Thread John Ladasky
On Nov 4, 10:21 am, de...@web.de (Diez B. Roggisch) wrote: > macm writes: >     for value in d.values(): >         if isinstance(value, dict): I'm not a Python guru, but... do you care that you're breaking duck typing here? I've had other programmers warn me against using isinstance() for this

Re: How find all childrens values of a nested dictionary, fast!

2010-11-04 Thread Arnaud Delobelle
macm writes: > Hi Folks > > How find all childrens values of a nested dictionary, fast! > a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}}

Re: How find all childrens values of a nested dictionary, fast!

2010-11-04 Thread Peter Otten
macm wrote: > About Peter script > > I am receiving > for v in f(a['a']['b']): > ... b.extend(v) > ... > Traceback (most recent call last): > File "", line 2, in > TypeError: 'int' object is not iterable > > I am trying understand this error. You are probably mixing Diez' implement

Re: How find all childrens values of a nested dictionary, fast!

2010-11-04 Thread macm
Peter Ok! Both works fine! Thanks a lot! >>> for v in f(a['a']['b']): ... b.extend(v) b Now I will try find which script is the fast! Regards macm On 4 nov, 15:56, macm wrote: > Hi Folks > > Thanks a lot > > Script from Diez works: > > print list(f(a)) > > but should be > > print lis

Re: How find all childrens values of a nested dictionary, fast!

2010-11-04 Thread macm
Hi Folks Thanks a lot Script from Diez works: print list(f(a)) but should be print list(f(a['a']['b'])) to fit my example. About Peter script I am receiving >>> for v in f(a['a']['b']): ... b.extend(v) ... Traceback (most recent call last): File "", line 2, in TypeError: 'int' obj

Re: How find all childrens values of a nested dictionary, fast!

2010-11-04 Thread Peter Otten
macm wrote: > How find all childrens values of a nested dictionary, fast! > a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} a['a'] > {'c': {'/':

Re: How find all childrens values of a nested dictionary, fast!

2010-11-04 Thread Diez B. Roggisch
macm writes: > Hi Folks > > How find all childrens values of a nested dictionary, fast! There is no faster than O(n) here. > a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, 'ab' : {'/' :[12,13,1