def linenumber_lookup(linenumbers, filepos):
    """
    >>> linenumbers = [0, 4, 7, 9]
    >>> linenumber_lookup(linenumbers, 3)
    1
    >>> linenumber_lookup(linenumbers, 8)
    3
    >>> linenumber_lookup(linenumbers, 33)
    -1

    """
    foundlinenumber = -1
    for idx, linestartpos in enumerate(linenumbers):
        try:
            if filepos >= linestartpos and filepos <= linenumbers[idx + 1]:
                foundlinenumber = idx + 1
        except IndexError as e:
            if filepos <= linestartpos:
                foundlinenumber = idx
            else:
                foundlinenumber = -1
    return foundlinenumber
