ある種の論理エラーが発生しており、それを特定できないようです。ここに私が持っているものがあります:
Document = 'Sample1'
locationslist = []
thedictionary = []
userword = ['the', 'a']
filename = 'Sample1'
for inneritem in userword:
thedictionary.append((inneritem,locationslist))
for position, item in enumerate(file_contents):
if item == inneritem:
locationslist.append(position)
wordlist = (thedictionary, Document)
print wordlist
したがって、基本的に、特定のユーザーワードと一緒に小さなリスト (locationslist) から大きなリスト (thedictionary) を作成しようとしています。出力がすべての単語のすべての場所をすべてのリストに入れていることを除いて、私はほとんどそれを持っています(2つしかありません -'the'
と'a'
)。単純なロジックの問題があるようですが、見つけられないようです。出力は次のとおりです。
([('the', [5, 28, 41, 97, 107, 113, 120, 138, 141, 161, 2, 49, 57, 131, 167, 189, 194, 207, 215, 224]),
('a', [5, 28, 41, 97, 107, 113, 120, 138, 141, 161, 2, 49, 57, 131, 167, 189, 194, 207, 215, 224])],
'Sample1')
しかし、次のようにする必要があります。
([('the', [5, 28, 41, 97, 107, 113, 120, 138, 141, 161]),
('a', [2, 49, 57, 131, 167, 189, 194, 207, 215, 224])],
'Sample1')
'the'
各ユーザーワードと'a'
?に関する問題のある出力のそれぞれに、両方の位置リストがどのように追加されているかを確認してください。ここで間違っていることについてアドバイスを使用できます..