这里的for循环主要目的是遍历列表的值,但是第一个键值对的值不是列表,有什么方法可以跳过第一个键,从第二键开始吗?
agent = {'number': '1001',
'agent_name': ['one', 'two', 'three'],
'agent_city': ['x', 'y', 'z'],
}
for na, ci in agent.items():
print(na.title() + ", nice to meet you")
for cii in ci:
print('\t' + cii)
agent = {'number': '1001',
'agent_name': ['one', 'two', 'three'],
'agent_city': ['x', 'y', 'z'],
}
for na, ci in agent.items():
if isinstance(ci, list): # 判断值的类型
print(na.title() + ", nice to meet you")
for cii in ci:
print('\t' + cii)
把第一个键值对删除从字典中移除进行循环就可以了啊,或者从1开始循环
加一个if 判断,当 type (ci) 不为列表时跳过