【发布时间】:2017-05-19 09:55:36
【问题描述】:
我有一个包含几列的大型数据库,我需要其中 2 列的数据。
最终结果是有 2 个下拉菜单,其中第一个设置“名称”,第二个是已合并到名称中的“数字”值。我只需要可用的数据,以便将其输入到另一个程序中。
因此是一个列表或字典,其中包含“名称”列表的唯一值,并附有数字列表中的数字。
# Just a list of random names and numbers for testing
names = [
"Cindi Brookins",
"Cumberband Hamberdund",
"Roger Ramsden",
"Cumberband Hamberdund",
"Lorean Dibble",
"Lorean Dibble",
"Coleen Snider",
"Rey Bains",
"Maxine Rader",
"Cindi Brookins",
"Catharine Vena",
"Lanny Mckennon",
"Berta Urban",
"Rey Bains",
"Roger Ramsden",
"Lanny Mckennon",
"Catharine Vena",
"Berta Urban",
"Maxine Rader",
"Coleen Snider"
]
numbers = [
6,
5,
7,
10,
3,
9,
1,
1,
2,
7,
4,
2,
8,
3,
8,
10,
4,
9,
6,
5
]
因此,在上面的示例中,“Berta Urban”会出现一次,但仍然分配了数字 8 和 9,“Rey Bains”将出现 1 和 3。
我试过了
mergedlist = dict(zip(names, numbers))
但这只会将最后一个数字分配给名称。
我不确定我是否可以制作一个包含多个“数字”的唯一“名称”的字典。
【问题讨论】:
标签: python-2.7