l = [('The', 'B-NP'), ('Mitsubishi', 'I-NP'), ('Electric', 'I-NP'), (
    'Company', 'I-NP'), ('Managing', 'B-NP'), ('Director', 'I-NP'), ('ate',
    'B-VP'), ('ramen', 'B-NP')]
list(extract_chunks(l, 'NP'))
l = [('What', 'B-NP'), ('is', 'B-VP'), ('the', 'B-NP'), ('airspeed', 'I-NP'
    ), ('of', 'B-PP'), ('an', 'B-NP'), ('unladen', 'I-NP'), ('swallow',
    'I-NP'), ('?', 'O')]
list(extract_chunks(l, 'NP'))
How to extract chunks from BIO chunked sentences? - python