开发者

What datatype is the output?

 pos_tag(word_tokenize("John's big idea isn't all that bad.")) 
 [('John', 'NNP'), ("'s", 'POS'), ('big', 'JJ'), ('idea', 'NN'), ('is',
 'VBZ'), ("n't", 'RB'), ('all', 'DT'), ('that', 'DT'), ('bad', 'JJ'),
 ('.', '.')]

Don't recognize the syntax at all. How would I iterate over this checking for JJ in 2nd val开发者_如何学Pythonue in the pairs.


It looks like a list of pairs (tuple of size 2).

Iterating over it is simple:

for text, type in pos_tag(word_tokenize("John's big idea isn't all that bad.")):
    if type == 'JJ':
        print 'text:', text
        print 'type:', type


Looks like a list of 2-tuples to me.

[x for x in L if x[1] == 'JJ']


list_values = [
    ('John', 'NNP'),
    ("'s", 'POS'),
    ('big', 'JJ'),
    ('idea', 'NN'),
    ('is', 'VBZ'),
    ("n't", 'RB'), 
    ('all', 'DT'),
    ('that', 'DT'),
    ('bad', 'JJ'),
    ('.', '.')
]
for (a, b) in list_values:
    if b == 'JJ':
        DoSomething(a,b)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜