def extra_credit(grades,students,bonus):
    """
    Returns a copy of grades with extra credit assigned

    The dictionary returned adds a bonus to the grade of
    every student whose netid is in the list students.

    Parameter grades: The dictionary of student grades
    Precondition: grades has netids as keys, ints as values.

    Parameter netids: The list of students to give extra credit
    Precondition: netids is a list of valid (string) netids

    Parameter bonus: The extra credit bonus to award
    Precondition: bonus is an int
    """
    # DICTIONARY COMPREHENSION
    #return { k:(grades[k]+bonus if k in students else grades[k]) for k in grades }

    # ACCUMULATOR PATTERN
    result = {}
    for k in  grades:
        if k in students:
            result[k] = grades[k]+bonus
        else:
            result[k] = grades[k]
    return result