<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_account(config, environment, stage=None):
 """Find environment name in config object and return AWS account."""

    if environment is None and stage:
        environment = get_environment(config, stage)
    account = None
    for env in config.get('environments', []):
        if env.get('name') == environment:
            account = env.get('account')
            role = env.get('role')
            username = os.environ.get(env.get('rs_username_var')) \
                if env.get('rs_username_var') else None
            apikey = os.environ.get(env.get('rs_apikey_var')) \
                if env.get('rs_apikey_var') else None
    if not account:
        sys.exit(ACCT_NOT_FOUND_ERROR.format(environment))
    return account, role, username, apikey