私は以下のリストを持っています。Pythonのリストでの正規表現の部分文字列一致のエラー
mylist = [["the", "and" "fresh milk", "a loaf of bread", "the butter"], ["an apple", "eggs", "oranges", "cup of tea"]]
は今、私は私の新しいリストは以下のようになるように、mylist
でストップワードを削除します。
mylist = [["fresh milk", "loaf bread", "butter"], ["apple", "eggs", "oranges", "cup tea"]]
私の現在のコードは以下の通りです。
cleaned_mylist= []
stops = ['a', 'an', 'of', 'the']
pattern = re.compile(r'|'.join([r'(\s|\b){}\b'.format(x) for x in stops]))
for item in mylist:
inner_list= []
for words in item:
inner_list.append(pattern.sub('', item).strip())
cleaned_mylist.append(inner_list)
ただし、コードは機能していないようです。私を助けてください。
あなたは、コードが動作していないと言うとき、あなたは何を意味するのですか?何が起こっている? –