codelifevcd
codelifevcd

Reputation: 317

How delete word ending with precise chars in list of tuples?

I have a list of tuple:

sent = [("Faire", 'VERB'),
 ("la", 'DET'),
 ("peinture", 'NOUN'),
 ("de", 'ADP'),
 ("la", 'DET'),
 ("voiture", 'NOUN')]

I would like to have a comprehension giving a list of words as result. And I want to skip 'VERB' ending with 're'.

I tried this, but have a boolean:

sent_clean = [not x.endswith('re') for (x,y) in sent if y in ['VERB']]

Expected output:

["la", "peinture", "de", "la", "voiture"]

How can I do this ?

Upvotes: 0

Views: 16

Answers (1)

Sayse
Sayse

Reputation: 43320

The left hand side of the list comprehension is the elements you want to end up with, the right hand side is for conditions

sent_clean =  [x for (x,y) in sent if not (y == 'VERB' and x.endswith('re'))]

Upvotes: 2

Related Questions