Maybe could be simplified with something like

    if var[0] == '$':
        return variables.get(var[1:], var)