Get keys from a dicionary

macm moura.mario at gmail.com
Fri Nov 11 11:38:41 EST 2011


Ok Sorry!!

Sorry the noise!!


def func(object):
    print "%s" % object


Regards



On Nov 11, 2:33 pm, macm <moura.ma... at gmail.com> wrote:
> Hi
>
> Sorry ! My mistake.
>
> >>> myDict = {}
> >>> myDict['foo'] = {}
> >>> myDict['foo']['bar'] = 'works'
>
> -----
>
> >>> def myFunction( MyObj ):
>
> ...     # MyObj is a nested dicionary (normaly 2 steps like myDict['foo']
> ['bar'])
> ...     # I want inspect this MyObj
> ...     # what keys was pass
> ...     print MyObj.keys() ## WRONG
> ...     # So What I want is :
> ...     # return foo bar
>
> ----------------
>
> >>> result = myFunction( myDict['foo']['bar'] )
> >>> result
>
> Should print :
>
> ... foo bar
>
> Best Regards
>
> macm
>
> On Nov 11, 2:09 pm, Jon Clements <jon... at googlemail.com> wrote:
>
>
>
>
>
>
>
> > On Nov 11, 1:31 pm, macm <moura.ma... at gmail.com> wrote:
>
> > > Hi Folks
>
> > > I pass a nested dictionary to a function.
>
> > > def Dicty( dict[k1][k2] ):
> > >         print k1
> > >         print k2
>
> > > There is a fast way (trick) to get k1 and k2 as string.
>
> > > Whithout loop all dict. Just it!
>
> > > Regards
>
> > > macm
>
> > I've tried to understand this, but can't tell if it's a question or
> > statement, and even then can't tell what the question or statement
> > is...
>
> > Care to eloborate?




More information about the Python-list mailing list