def selectByMatchingPrefix(param, opts):
    """
    Given a string parameter and a sequence of possible options, returns an option that is uniquely
    specified by matching its prefix to the passed parameter.

    The match is checked without sensitivity to case.

    Throws IndexError if none of opts starts with param, or if multiple opts start with param.

    >> selectByMatchingPrefix("a", ["aardvark", "mongoose"])
    "aardvark"
    """
    lparam = param.lower()
    hits = [opt for opt in opts if opt.lower().startswith(lparam)]
    nhits = len(hits)
    if nhits == 1:
        return hits[0]
    if nhits:
        raise IndexError("Multiple matches for for prefix '%s': %s" % (param, hits))
    else:
        raise IndexError("No matches for prefix '%s' found in options %s" % (param, opts))