def valid2(s, c, pos1, pos2):
    """
    From the string `s` extract the characters at (1-indexed) positions `pos1` and `pos2`.
    Return True when exactly one of these characters matches the test character `c`, otherwise False
    """
    return (s[pos1 - 1] == c) ^ (s[pos2 - 1] == c)