Python 3.5 iterate through a list of dictionaries

前端 未结 4 1327
深忆病人
深忆病人 2020-12-23 10:34

My code is

index = 0
for key in dataList[index]:
    print(dataList[index][key])

Seems to work fine for printing the values of dictionary k

4条回答
  •  忘掉有多难
    2020-12-23 11:06

    You can easily do this:

    for dict_item in dataList:
      for key in dict_item:
        print dict_item[key]
    

    It will iterate over the list, and for each dictionary in the list, it will iterate over the keys and print its values.

提交回复
热议问题