def last_non_space(s,i):
    """
    :param s: string
    :param i: index
    :return: A pair of (the last character before s[i] that is not a space, its index)
    """
    i -= 1
    while i >= 0 and (s[i] == ' ' or s[i] == '\n'):
        i -= 1

    if i >= 0:
        return (s[i],i)
    else:
        return (None,-1)