Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

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'))]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading