import re


def collect_sentences_picsom(data):
    """Collect all sentences from MSR-VTT gt-* files. Captions are in the following format:
    Each line in text starts with a 4 digit number such as 0001 or 1234 etc, followed by
    captions separated by " # " , last caption is followed by EOL"""
    sentences = []
    for line in data:
        line = line.rstrip()
        # Match first non-space characters into one group, and captions into other:
        m = re.match('([^ ]+) (.*)', line)
        assert m, 'ERROR: Reading  gt input file failed'
        captions = m.group(2)
        current_sentences = captions.split(' # ')
        sentences = sentences + current_sentences

    return sentences