1

だから私は読んで辞書に入れる必要がある行を持っています.最初の数字はキーで、4番目の数字はキーに関連付けられる単語の量です.

f = open("wordnetSample.txt", "r")
D = {}
for line in f:
    L = line.split()
    D.update({L[0]: L[4:4 + 2 * int(L[3]):2]})

これらは私が辞書に入れている行のサンプルです

09826802 18 n 01 Areopagite 0 002 @ 10326901 n 0000 #m 08181009 n 0000 | a member of  the council of the Areopagus  
09826918 18 n 01 Argive 0 002 @ 09729560 n 0000 + 08804512 n 0101 | a native or inhabitant of the city of Argos  

これは私がこれまでにDのために持っているものです

{'09826802': ['Areopagite'], '09826918': ['Argive']}

そして、私はこれが欲しい:

{'09826802': ['Areopagite', 'a member of  the council of the Areopagus'], '09826918': ['Argive', 'a native or inhabitant of the city of Argos']}
4

2 に答える 2

1

これはやっている

D = {}
for line in f:
    L = line.split()
    L2 = line.split('|')
    D.update({L[0]: (L[4:4 + 2 * int(L[3]):2][0], L2[1].split('\n')[0])})

私は別の分割wrtを追加しました'|'

于 2013-06-05T15:07:21.600 に答える