Nested dictionary displays?

Robert Dailey rcdailey at gmail.com
Thu Jun 5 11:52:07 EDT 2008


Hi,

I'm using Python 3.0 (the latest as of now) and I have a very large
dictionary that I'm attempting to do some processing on. The dictionary
basically has strings in it, as well as other dictionaries which themselves
also have strings. Using a display, I'm trying to (with as little code
possible) make every single string in the entire dictionary tree lower case
by calling lower() on the string. However, python is not accepting my
syntax. How do I create nested displays? Thanks. The code is below. Note,
also, that the "path" key/value pair should be skipped. I need to lowercase
the 'path' key, but the value is not a tuple, and that value should be
skipped. The nested display/comprehension logic is at the very bottom.

stage_map = {
#------------------------------------------------------------------------------------------
    "system"            :   {   "path" :    "C:\mypath"
                            ,   "debug" :   ( "boost_system-mt-gyd.dll", )
                            ,   "release" : ( "boost_system-mt.dll", )
                            }
#------------------------------------------------------------------------------------------
,    "filesystem"        :  {   "path" :    "C:\mypath"
                            ,   "debug" :   ( "boost_filesystem-mt-gyd.dll",
)
                            ,   "release" : ( "boost_filesystem-mt.dll", )
                            }
#------------------------------------------------------------------------------------------
,    "librocket"         :  {   "path" :    "C:\mypath"
                            ,   "debug" :   ( "EMPCore_d.dll"
                                            , "EMPCorePython_d.dll"
                                            , "RocketCore_d.dll"
                                            , "RocketDebugger_d.dll"
                                            , "RocketControls_d.dll"
                                            )
                            ,   "release" : ( "EMPCore.dll"
                                            , "EMPCorePython.dll"
                                            , "RocketCore.dll"
                                            , "RocketDebugger.dll"
                                            , "RocketControls.dll"
                                            )
                            }
#------------------------------------------------------------------------------------------
}

# This does not compile...
stage_map = [i.lower() : [ii.lower() : [iii.lower() for iii in jj if
jj.lower() != "path"] for ii, jj in j] for i, j in stage_map]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080605/fba4ae22/attachment.html>


More information about the Python-list mailing list