以下是一个使用Python编程语言的示例代码,用于记录不同城市的候选人名单:
# 创建一个空字典来存储不同城市的候选人名单
candidates_by_city = {}
# 添加不同城市的候选人名单
candidates_by_city['北京'] = ['张三', '李四', '王五']
candidates_by_city['上海'] = ['赵六', '钱七', '孙八']
candidates_by_city['广州'] = ['周九', '吴十', '郑十一']
# 打印不同城市的候选人名单
for city, candidates in candidates_by_city.items():
print(f"{city}的候选人名单:")
for candidate in candidates:
print(candidate)
print()
运行以上代码会输出以下结果:
北京的候选人名单:
张三
李四
王五
上海的候选人名单:
赵六
钱七
孙八
广州的候选人名单:
周九
吴十
郑十一
这段代码使用了字典数据结构来存储不同城市的候选人名单。每个城市作为字典的键(key),对应的候选人名单作为字典的值(value)。通过使用循环遍历字典的键和值,可以打印出每个城市的候选人名单。