'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 ?
Solution 1:[1]
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'))]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sayse |
