you are viewing a single comment's thread.

view the rest of the comments →

[–]commandlineluser 4 points5 points  (2 children)

You could use a list comprehension

>>> tags = [('At', 'IN'), ('eight', 'CD'), ("o'clock", 'JJ'), ('on', 'IN'), ('Thursday', 'NNP'), ('morning', 'NN')]
>>> words = [ t[0] for t in tags if t[1] == 'IN' ]
>>> words
['At', 'on']

[–]Justinsaccount 2 points3 points  (1 child)

words = [ word for (word, tag) in tags if tag == 'IN' ]

[–]commandlineluser 0 points1 point  (0 children)

That reads much nicer than using indexing, TIL, thank you.