这是我的字典
{'www.pic2fly.com/Weather+Of+Bahawalpur.html': ['https://tse1.mm.bing.net/th?
id=OIP.RsEykDoK1xxg2zivHYW7WwEsC5&pid=Api'], 'panoramio.com/photo/84118355':
['https://tse2.mm.bing.net/th?id=OIP.1683LeSgJHoFhxX-tKhGSAEsDh&pid=Api'], 'nativepakistan.com/photos-of-bahawalpur': ['https://tse3.mm.bing.net/th?id=OIP.wS0pep46eEsGSSY39RNxLQEsDQ&pid=Api', 'https://tse2.mm.bing.net/th?id=OIP.Zn5zIzevX8HqUnwCyRZ3QwEsDJ&pid=Api', 'https://tse1.mm.bing.net/th?id=OIP.671-BIumri8_oRAQRLd-ggEsDJ&pid=Api', 'https://tse3.mm.bing.net/th?id=OIP.0dShzaFVWKBtTSxnOFHyaAEsDI&pid=Api', 'https://tse1.mm.bing.net/th?id=OIP.LXLVj2t-dawxlMcJp1GBTAEsDV&pid=Api', 'https://tse4.mm.bing.net/th?id=OIP.Z0-Y7RzbFM43N6YFNevsTQEsDL&pid=Api', 'https://tse1.mm.bing.net/th?id=OIP.AYjL8nxCNUE-HvEiifvqWQEsCc&pid=Api', 'https://tse4.mm.bing.net/th?id=OIP.Iy9NYKksUM3TSpgmOc0-JgDZEs&pid=Api', 'https://tse3.mm.bing.net/th?id=OIP.NHdCNr5g2CYn3L6wP77BygEsDg&pid=Api']}
使用for循环我打印这样的值
for key in res.iterkeys():
print key
for value in res.itervalues():
print value
我需要这个作为输出
www.pic2fly.com/Weather+Of+Bahawalpur.html
https://tse3.mm.bing.net/th?id=OIP.wS0pep46eEsGSSY39RNxLQEsDQ&pid=Api
panoramio.com/photo/84118355
https://tse2.mm.bing.net/th?id=OIP.Zn5zIzevX8HqUnwCyRZ3QwEsDJ&pid=Api
nativepakistan.com/photos-of-bahawalpur
https://tse1.mm.bing.net/th?id=OIP.671-BIumri8_oRAQRLd-ggEsDJ&pid=Api
https://tse3.mm.bing.net/th?id=OIP.0dShzaFVWKBtTSxnOFHyaAEsDI&pid=Api
https://tse1.mm.bing.net/th?id=OIP.LXLVj2t-dawxlMcJp1GBTAEsDV&pid=Api
....
我刚开始学习字典请帮忙
答案 0 :(得分:2)
# iterate the dictionary with the key and val at the same time
for key, val in res.items():
# print the key
print key
for x in val:
# iterate the list of the val and print all items
print x
答案 1 :(得分:0)
您正在尝试打印值为列表的字典中的所有值。我们这样做的方式是:
for key in my_dict:
print key
for list_value in my_dict[key]:
print list_value
my_dict[key]
答案 2 :(得分:0)
好的,如果你打电话给你的dictionnary,你可以这样做:
for i in a:
print(i)
for j in a[i]:
print(j)
如果您使用的是python 2.X,则可以使用print
删除括号