def next_labels(labelsfile):
    '\n        Generator for label sets from the label file\n    '
    labels_reader = csv.reader(labelsfile)
    next(labels_reader)
    first_label_line = next(labels_reader)
    cur_subj = int(first_label_line[0])
    cur_hadm = int(first_label_line[1])
    cur_labels = [first_label_line[2]]
    for row in labels_reader:
        subj_id = int(row[0])
        hadm_id = int(row[1])
        code = row[2]
        if ((hadm_id != cur_hadm) or (subj_id != cur_subj)):
            (yield (cur_subj, cur_labels, cur_hadm))
            cur_labels = [code]
            cur_subj = subj_id
            cur_hadm = hadm_id
        else:
            cur_labels.append(code)
    (yield (cur_subj, cur_labels, cur_hadm))
Generator for label sets from the label file
def next_labels(labelsfile):
    '\n        \n    '
    labels_reader = csv.reader(labelsfile)
    next(labels_reader)
    first_label_line = next(labels_reader)
    cur_subj = int(first_label_line[0])
    cur_hadm = int(first_label_line[1])
    cur_labels = [first_label_line[2]]
    for row in labels_reader:
        subj_id = int(row[0])
        hadm_id = int(row[1])
        code = row[2]
        if ((hadm_id != cur_hadm) or (subj_id != cur_subj)):
            (yield (cur_subj, cur_labels, cur_hadm))
            cur_labels = [code]
            cur_subj = subj_id
            cur_hadm = hadm_id
        else:
            cur_labels.append(code)
    (yield (cur_subj, cur_labels, cur_hadm))