def _filtered_accounts(
    accounts: Iterable[CacheItem], username: Optional[str] = None, tenant_id: Optional[str] = None
) -> List[CacheItem]:
    """Return accounts matching username and/or tenant_id.

    :param accounts: accounts from the MSAL cache
    :type accounts: Iterable[CacheItem]
    :param str username: an account's username
    :param str tenant_id: an account's tenant ID
    :return: accounts matching username and/or tenant_id
    :rtype: list[CacheItem]
    """

    filtered_accounts = []
    for account in accounts:
        if username and account.get("username") != username:
            continue
        if tenant_id:
            try:
                _, tenant = account["home_account_id"].split(".")
                if tenant_id != tenant:
                    continue
            except Exception:  # pylint:disable=broad-except
                continue
        filtered_accounts.append(account)
    return filtered_accounts
Return accounts matching username and/or tenant_id.

    :param accounts: accounts from the MSAL cache
    :type accounts: Iterable[CacheItem]
    :param str username: an account's username
    :param str tenant_id: an account's tenant ID
    :return: accounts matching username and/or tenant_id
    :rtype: list[CacheItem]
    
Solutions/CyberArkAudit/Data Connectors/.python_packages/lib/site-packages/azure/identity/_internal/shared_token_cache.py