<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def average(sequence, key):
 """Averages a sequence based on a key."""

    return sum(map(key, sequence)) / float(len(sequence))