遍历列表,打印:我叫name,今年age岁,家住dizhi,电话phone(我是通过下标取键得到对应值,有哪位大神来个更简单的)

时间:2022-05-20 11:26:40

lt = [
{'name':'小王', 'age':18, 'info':[('phone', '123'), ('dizhi', '广州')]},
{'name':'小芳', 'age':19, 'info':[('phone', '789'), ('dizhi', '深圳')]},
{'name':'小杜', 'age':22, 'info':[('phone', '567'), ('dizhi', '北京')]},
{'name':'小孟', 'age':28, 'info':[('phone', '000'), ('dizhi', '上海')]},
{'name':'小乔', 'age':26, 'info':[('phone', '111'), ('dizhi', '河南')]},
]

 

 

i = len(lt)
for b in range(i):
print('我叫{},今年{}岁,家住{},电话{}'.format(lt[b].get("name"), lt[b].get("age"), lt[b].get("info")[1][1],lt[b].get("info")[0][1]) )