Python 如何在字典列表中打印字典值?
我有一个字典列表,我想打印每个字典中的某些键:Python 如何在字典列表中打印字典值?,python,list,dictionary,Python,List,Dictionary,我有一个字典列表,我想打印每个字典中的某些键: dict_results=[{'terms':['hi','bye'],'title':'01234def','text':'hello, how are you?'},{'terms':...}...] 这不起作用: for item in dict_results: print "{0},{1}".format(item[0]['title'],item[0]['text']) 键错误:0在列表中循环,然后访问每个字典的键: >
dict_results=[{'terms':['hi','bye'],'title':'01234def','text':'hello, how are you?'},{'terms':...}...]
这不起作用:
for item in dict_results:
print "{0},{1}".format(item[0]['title'],item[0]['text'])
键错误:0在
列表中循环,然后访问每个字典的键:
>>> dict_results=[{'terms':['hi','bye'],'title':'01234def','text':'hello, how are you?'},
... {'terms':0, 'title':'hello', 'text':'world'}]
>>> for d in dict_results:
... print(d['title'], d['text'])
...
01234def hello, how are you?
hello world
循环浏览列表
,然后访问每个字典的键:
>>> dict_results=[{'terms':['hi','bye'],'title':'01234def','text':'hello, how are you?'},
... {'terms':0, 'title':'hello', 'text':'world'}]
>>> for d in dict_results:
... print(d['title'], d['text'])
...
01234def hello, how are you?
hello world
循环浏览列表
,然后访问每个字典的键:
>>> dict_results=[{'terms':['hi','bye'],'title':'01234def','text':'hello, how are you?'},
... {'terms':0, 'title':'hello', 'text':'world'}]
>>> for d in dict_results:
... print(d['title'], d['text'])
...
01234def hello, how are you?
hello world
循环浏览列表
,然后访问每个字典的键:
>>> dict_results=[{'terms':['hi','bye'],'title':'01234def','text':'hello, how are you?'},
... {'terms':0, 'title':'hello', 'text':'world'}]
>>> for d in dict_results:
... print(d['title'], d['text'])
...
01234def hello, how are you?
hello world
删除[0]
,项
不是数组。删除[0]
,项
不是数组。删除[0]
,项
不是数组。删除[0]
,项
不是数组。谢谢你的解决方案,但我必须使用另一个,因为它是我如何构造问题的。谢谢你的解决方案,但我必须使用另一个,因为它是我如何构造问题的。谢谢你的解决方案,但我必须使用另一个,因为它是我如何构造问题的。谢谢您的解决方案,但我必须使用另一个,因为这是我如何组织我的问题。