for site_listing in all_sites:
    if site.getName() == site_listing.getName() and site.getCustomer().getId(
        ) == site_listing.getCustomer().getId():
        if not site.getId():
            site.setId(site_listing.getId())
if site.getId() == site_listing.getId():
    return site_listing
The Pythonic way of validating a long chain of conditions in Python