1

モイコードにタプルがあります:

('H', 'NNP')

これはコードです:

# -*- coding: utf-8 -*-
from nltk.corpus import wordnet as wn
from nltk import pos_tag
import nltk
syno =[]


sentence = '''His father suggested he study to become a parson instead, but Darwin was far more inclined to study natural history.DarwinDar·win (där'wĭn),Charles Robert.1809-1882.British naturalist who revolutionized the study of biology with his theory ofevolutionbased on natural selection
Like several scientists before him, Darwin believed all the life on earth evolved (developed gradually) over millions of years from a few common ancestors.'''
sent = pos_tag(sentence)

alpha = [s for s in sent if s[1] == 'NNP']
for i in range(0,len(alpha)-1):
    print alpha[i] #return the tuple

ここから H だけを削除したい。どうすればそうできますか?

4

3 に答える 3

1

タプルは不変であるため、新しいものを作成する必要があります。

>>> t = ('H', 'NNP')
>>> tuple(x for x in t if x != 'H')
('NNP',)
>>> z = tuple(x for x in t if x == 'H')
>>> z
('H',)
>>> z[0]
'H'
>>>
于 2013-08-15T15:55:10.367 に答える
0
>>> x = ('H', 'NNP')
>>> x = tuple(list(x)[1:])
>>> x
('NNP',)
于 2013-08-15T16:16:24.003 に答える