def char_weight(string, index):
    """Return a weight of 0-2 for the char at the given index, used for deciding quote direction"""

    if index < 0 or index >= len(string):
        return 0
    if string[index] == ' ':
        return 0
    if string[index].isalnum():
        return 2
    return 1