def interp(mapping, x):
mapping = sorted(mapping)<EOL>if len(mapping) == <NUM_LIT:1>:<EOL><INDENT>xa, ya = mapping[<NUM_LIT:0>]<EOL>if xa == x:<EOL><INDENT>return ya<EOL><DEDENT>return x<EOL><DEDENT>for (xa, ya), (xb, yb) in zip(mapping[:-<NUM_LIT:1>], mapping[<NUM_LIT:1>:]):<EOL><INDENT>if xa <= x <= xb:<EOL><INDENT>return ya + float(x - xa) / (xb - xa) * (yb - ya)<EOL><DEDENT><DEDENT>return x<EOL>
Compute the piecewise linear interpolation given by mapping for input x.

    >>> interp(((1, 1), (2, 4)), 1.5)
    2.5