Table = u'''A,This is A
B,This is B
C,This is C
D,This is D
E,This is E
F,This is F
G,This is G
H,This is H
I,This is I
J,This is J'''
SearchValue = u'''A
B
C
D
Bang
F
Bang
G
H'''
Table = Table.splitlines()
LineText = {}
for targetLineText in Table:
LineText[targetLineText.split(',')[0]] = targetLineText.split(',')[1]
SearchValue = SearchValue.splitlines()
for targetValue in SearchValue:
print LineText[targetValue] if targetValue in LineText else 'Error:' + targetValue
這段代碼是幹什麼獲取字典值的表現...... 它找到值列表從「表」字典的鍵名爲「SearchValue」最好在python
我檢查鍵存在以下代碼..
targetValue in LineText
我想要做的是在關鍵值存在檢查的同時獲取值。因爲我認爲這表現更好。
這正是我一直在尋找。謝謝。 – Nigiri 2012-02-16 11:15:59