使用Python 2.7,我有一個任意長的元組的列表(t)其中:列表元組來解釋與綜合鍵
t[0] --> first_name_id
t[1] --> first_name
t[2] --> last_name_id
t[3] --> last_name
first_name_id和FIRST_NAME應該是集合中是唯一的,但last_name_id和last_name是獨一無二的只在first_name_id/first_name內。
正如你可以看到下面,有一個簡的姓氏是「史密斯」,但ID爲3,而對於「湯姆」的ID爲「史密斯」是「0」
t = [('1', 'Tom', '0', 'Smith'),
('1', 'Tom', '1', 'Johnson'),
('1', 'Tom', '2', 'Williams'),
('32', 'Jane', '0', 'Brown'),
('32', 'Jane', '1', 'David'),
('32', 'Jane', '3', 'Smith'),
.
.
.
]
我米attepting鞏固這一進一本字典,這樣我可以很快通過FIRST_NAME和姓氏找到ID的元組:
所以,我的數據結構將是:
data_structure = {
"Tom": {"first_name_id": "1", "surnames": {"Smith": "0", "Johnson": "1", "Williams": "3"}},
"Jane": {"first_name_id": "32", "surnames": {"Brown": "0", "David": "1", "Smith": "3"}}
}
output = data_structure["Tom"]["first_name_id"],data_structure["Tom"]["surnames"]["Williams"]
print output
>>> ('1', '3')
但究竟是什麼你遇到的麻煩是什麼? – jmoon