Python dict query and assign values problems
Hi guys, I have python dict query and assign values problems, I defined a dict
key_words_list = {
'key description1':'key1',
'key description2':'key2',
'key description3':'key3',
....
...
...
#about 150 keys
}
Then I'll search keys in inputfile which has the following format:
Key description1 10 30 20
Key description5 10 30 50
Key description7 10 30 50
Key description2 14 33 20
Key description4 15 30 50
Key description3 3 30 30
Key description6 10 30 50
Key description8 10 30 80
Now my question is
1)Can I use value in dic as arrray?
For example, can I write codes like this?
for i, key, value in key_words_list:
values[i] = 'some words'
2) If 1st answer is yes, this program can be written in C/C++ style
for line in lines:
for key,value in key_words_list:
if line.startwith(key)
value[0] = "word1"
value[1] = "word2"
BUT, is there any better pythonic style to implement this functionality?
Thanks a lot!!!
Last edited by ArthurHuang; 03-11-2012 at 05:13 PM.
|