def form_to_grade_assignment(form):
    """Creates a grade dict from an assignment form."""
    grade_id = '{student}-{assignment}-{course}'.format(**form)
    grade = {'_id': grade_id,
             'student': form['student'],
             'assignment': form['assignment'],
             'course': form['course'],
            }
    if form['filename']:
        grade['filename'] = form['filename']
    scores = {int(k[5:]): float(v) for k, v in form.items() if k.startswith('score')}
    scores = sorted(scores.items())
    grade['scores'] = [v for _, v in scores]
    return grade