简体   繁体   中英

Python dictionary print with parentheses

I am trying to edit this function so the values of the dictionary will not be printed in parentheses and will be iterable:

def traverse_appended(key):
reg_dict = {}
#keypath = r"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
for item in traverse_reg(key):
    keypath_str = str(keypath+item)
    reg_dict[item] = str(get_reg("Displayversion", keypath_str)), str(get_reg("DisplayName", keypath_str))
    #reg_dict[item] = get_reg("DisplayName", keypath_str)

return reg_dict

the expected output is :

{'DXM_Runtime': 'None', 'None'}

The function output:

{'DXM_Runtime': ('None', 'None')}
#Consider traverse_appended returns following dict.
#I think, converting func_dict values which are tuple into string, will help you to get expected  output.

func_dict = {"DXM_Runtime":('None','None'),
             "TMP_KEY":('A','B')
             }

derived_dict = {}
for k,v in func_dict.viewitems():
    tmp_str = ",".join(v)
    derived_dict[k] = tmp_str

print derived_dict

#Output

E:\tmp_python>python tmp.py

{'DXM_Runtime': 'None,None', 'TMP_KEY': 'A,B'}

#If this doesn't help you, then please post the code for get_reg and traverse_reg function also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM