Print list items - python -


i have list 2 item, each item dictionary. want print item these dicts, python writes dicts , not name. suggestion?

sep_st = {0.0: [1.0, 'lbrg'], 0.26: [31.0, 'stig']}     sep_dy = {0.61: [29.0, 'stig'], 0.09: [25.0, 'stig']} sep = [sep_st, sep_dy] item in sep:   values in sorted(item.keys()):      p.write (str(item)) # here want write name of list element file      p.write (str(values))     p.write (str(item[values]) +'\n' ) 

my suggestion use dict sep, instead of list. way make dict names string-keys them:

sep_st = {0.0: [1.0, 'lbrg'], 0.26: [31.0, 'stig']}     sep_dy = {0.61: [29.0, 'stig'], 0.09: [25.0, 'stig']} sep = {"sep_st": sep_st, "sep_dy": sep_dy} # dict instead of list item in sep:   values in sorted(sep[item].keys()):      p.write (str(item))     p.write (str(values))     p.write (str(sep[item][values]) +'\n') 

as can see in this other question, it's impossible access instance names, unless subclass dict , pass name constructor of custom class, custom dict instance can have name can have access to.

so in case, suggest use dicts name-keys store dicts, instead of list.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -