私はタプルの次のリストを持っている:('iphone', 'device'), ('pixel', 'device'), ('google', 'entity')
に('iphone', 'X'), ('pixel', 'X'), ('google', 'NOUN')
:タプルのリストの値を変更するにはどうすればよいですか?
lis = [('The', 'DET'),
('iphone', 'X'),
('is', 'VERB'),
('a', 'DET'),
('very', 'ADV'),
('nice', 'ADJ'),
('device', 'NOUN'),
('.', 'PUNCT'),
('However', 'ADP'),
('the', 'DET'),
('pixel', 'X'),
('is', 'VERB'),
('by', 'ADP'),
('far', 'ADV'),
('more', 'ADV'),
('interesting', 'ADJ'),
('since', 'ADV'),
('it', 'PRON'),
('was', 'AUX'),
('made', 'VERB'),
('by', 'ADP'),
('google', 'NOUN'),
('.', 'PUNCT')]
私の主な目的は、特にこのタプルの値を変更することです。私はそれが実際に('galaxy', 'device')
として、リストの最後に追加されtags['galaxy'] = 'device'
を追加
tags['Google'] = 'device'
tags['pixel'] = 'device'
tags['iphone'] = 'entity'
#this one is not present in lis . Nevertheless, I would like to add it just in case I need it.
tags['galaxy'] = 'device'
tags = list(tags.items())
tags = OrderedDict(postag(str(sample)))
ので:私は順序を保持に興味を持っていますので、このように、私は、次の試してみました。したがって、私の質問はどのように修正し、それらが存在する場合、タプルの値を更新できますか?
はにそれが必要ですタプルのリストを使用しますか?タプルは不変なので、設計上、私はそれらが変更される可能性があると分かっていれば使用しません。たとえば、辞書を使用してマッピングを格納したり、キーの順序を保持するための別のリストを使用することができます。 – MxyL
@MxyLはい、タプルが必要です...私はあなたのアイデアを理解しています。 –