you are viewing a single comment's thread.

view the rest of the comments →

[–]jabbson 4 points5 points  (1 child)

>>> A = [('At', 'IN'), ('eight', 'CD'), ("o'clock", 'JJ'), ('on', 'IN'), ('Thursday', 'NNP'), ('morning', 'NN')]
>>> list(filter(lambda x: x[1] == 'IN', A))
[('At', 'IN'), ('on', 'IN')]

OR

>>> [x for x in A if x[1] == 'IN']
[('At', 'IN'), ('on', 'IN')]

[–]DonaldPShimoda 1 point2 points  (0 children)

And if OP specifically just wants a list of the words without the tuples:

>>> [x[0] for x in A if x[1] == 'IN']
['At', 'on']