docs: def parse_ethnicity(parts):
    """
      Parse the ethnicity from the Backpage ad. Returns the higher level ethnicities associated with an ethnicity.
      For example, if "russian" is found in the ad, this function will return ["russian", "eastern_european", "white_non_hispanic"].
      This allows for us to look at ethnicities numerically and uniformally.
      Note: The code for this function is pretty old and messy, but still works well enough for our purposes.
        parts -> 
    """
  
    eastern_european = ['russian', 'ukrainian', 'moldova', 'bulgarian', 'slovakian', 'hungarian', 'romanian',
    'polish', 'latvian', 'lithuanian', 'estonia', 'czech', 'croatian', 'bosnian', 'montenegro', 'macedonian', 'albanian',
    'slovenian', 'serbian', 'kosovo', 'armenian', 'siberian', 'belarusian']
    western_european = ['british', 'german', 'france', 'greek', 'italian', 'belgian', 'netherlands', 'swiss', 'irish',
    'danish', 'sweden', 'finnish', 'norwegian', 'portugese', 'austrian', 'sanmarino', 'turkish', 'liechtenstein', 'australian',
    'newzealand', 'andorra', 'luxembourg', 'israeli', 'jewish']
    caribbean = ['bahamian', 'haitian', 'dominican', 'puertorican', 'jamaican', 'cuban', 'caymanislands', 'trinidad', 'caribbean',
    'guadeloupe', 'martinique', 'barbados', 'saintlucia', 'stlucia', 'curacao', 'aruban', 'saintvincent', 'stvincent', 'creole',
    'grenadines', 'grenada', 'barbuda', 'saintkitts', 'saintmartin', 'anguilla', 'virginislands', 'montserrat', 'saintbarthelemy']
    south_central_american = ['guatemalan', 'belizean', 'honduras', 'nicaraguan', 'elsalvador', 'panamanian', 'costarican',
    'colombian', 'columbian', 'venezuelan', 'ecuadorian', 'peruvian', 'bolivian', 'chilean', 'argentine', 'uruguayan', 'paraguayan',
    'brazilian', 'guyana', 'suriname']
    mexican = ['mexican']
    spanish = ['spanish']
    east_asian = ['thai', 'vietnamese', 'cambodian', 'malaysian', 'filipino', 'singaporean', 'indonesian', 'japanese',
    'chinese', 'taiwanese', 'northkorean', 'southkorean', 'korean']
    korean = ['northkorean', 'southkorean', 'korean']
    south_asian = ['nepalese', 'bangladeshi', 'bhutanese', 'indian']
    hawaiian_pacific_islanders = ['hawaiian', 'guamanian', 'newguinea', 'fiji', 'marianaislands', 'solomonislands', 'micronesia',
    'tuvalu', 'samoan', 'vanuata', 'polynesia', 'cookislands', 'pitcaimislands', 'marshallese']
    middle_eastern = ['iraqi', 'iranian', 'pakistani', 'afghan', 'kazakhstan', 'uzbekistan', 'tajikistan', 'turkmenistan',
    'azerbaijan', 'kyrgyzstan', 'syrian', 'lebanese', 'jordanian', 'saudiarabian', 'unitedarabemirates', 'bahrain', 'kuwait',
    'persian', 'kurdish', 'middleeastern']
    north_african = ['egyptian', 'libyan', 'algerian', 'tunisian', 'moroccan', 'westernsaharan', 'mauritanian', 'senegal', 'djibouti']
  
    # Broad, high level ethnicity classes
    white_non_hispanic = eastern_european + western_european
    hispanic_latino = caribbean + south_central_american + mexican + spanish
    # Get tribe names!!!
    american_indian = ['nativeamerican', 'canadian', 'alaskan', 'apache', 'aztec', 'cherokee', 'chinook', 'comanche',
    'eskimo', 'incan', 'iroquois', 'kickapoo', 'mayan', 'mohave', 'mojave', 'navaho', 'navajo', 'seminole']
    asian = east_asian + south_asian + hawaiian_pacific_islanders
    midEast_nAfrica = middle_eastern + north_african
    african_american = ['black', 'african american']
    ss_african = ['gambia', 'bissau', 'guinea', 'sierraleone', 'liberian', 'ghana', 'malian', 'burkinafaso', 'beninese', 'nigerian',
    'sudanese', 'eritrea', 'ethiopian', 'cameroon', 'centralafricanrepublic', 'somalian', 'gabon', 'congo', 'ugandan', 'kenyan',
    'tanzanian', 'rwandan', 'burundi', 'angola', 'zambian', 'mozambique', 'malawi', 'zimbabwe', 'namibia', 'botswana',
    'lesotho', 'southafrican', 'swaziland', 'madagascar', 'comoros', 'mauritius', 'saintdenis', 'seychelles', 'saotome']
  
    # Add various identifying values to Category lists
    white_non_hispanic.append('european')
    white_non_hispanic.append('white')
    hispanic_latino.extend(['hispanic', 'latina'])
    asian.extend(['asian', 'oriental'])
    midEast_nAfrica.extend(['arabian', 'muslim'])
  
    # "from ____" to handle false positives as names
    from_names = ['malaysia']
  
    # One massive ethnicities list
    ethnicities = white_non_hispanic + hispanic_latino + american_indian + asian + midEast_nAfrica + african_american + ss_african
  
    num = 0
    found = []
    # Check each part of the body
    clean_parts = []
    for p in parts:
      part = parser_helpers.clean_part_ethn(p)
      clean_parts.append(part)
  
      # handle "from _____" ethnicities to avoid false positives in names
      for name in from_names:
        if re.compile(r'from +' + re.escape(name)).search(part):
          found.append(name)
  
      if any(eth in part for eth in ethnicities):
        # At least one ethnicity was found
        for ethn in ethnicities:
          if ethn in part:
            index=part.index(ethn)
            if (' no ' in part and part.index(' no ')+4==index) or ('no ' in part and part.index('no')==0 and part.index('no ') + 3==index) or ('.no ' in part and part.index('.no ') + 4==index): 
              pass
            else:
            # Found the current ethnicity
              if ethn in ['black', 'african american']:
                ethn = "african_american"
              if ethn == 'white': 
                ethn = 'white_non_hispanic'
              if ethn not in found:
                # Add to Found list, check for subsets
                found.append(ethn)
                if ethn in eastern_european:
                  found.append("eastern_european")
                if ethn in western_european:
                  found.append("western_european")
                if ethn in caribbean:
                  found.append("caribbean")
                if ethn in south_central_american:
                  found.append("south_central_american")
                if ethn in east_asian:
                  found.append("east_asian")
                if ethn in south_asian:
                  found.append("south_asian_indian")
                if ethn in hawaiian_pacific_islanders:
                  found.append("hawaiian_pacific_islanders")
                if ethn in middle_eastern:
                  found.append("middle_eastern")
                if ethn in north_african:
                  found.append("north_african")
                # Check the most general ethnicity categories
                if ethn in white_non_hispanic and "white_non_hispanic" not in found:
                  found.append("white_non_hispanic")
                  num += 1
                if ethn in hispanic_latino and "hispanic_latino" not in found:
                  found.append("hispanic_latino")
                  num += 1
                if ethn in american_indian and "american_indian" not in found:
                  found.append("american_indian")
                  num += 1
                if ethn in asian and "asian" not in found:
                  if ethn != "asian":
                    found.append("asian")
                    num += 1
                if ethn in midEast_nAfrica and "midEast_nAfrican" not in found:
                  found.append("midEast_nAfrican")
                  num += 1
                if ethn in ss_african and "subsaharan_african" not in found:
                  found.append("subsaharan_african")
                  num += 1
                if ethn == "african_american":
                  num += 1
  
    # Remove ethnicity from all parts
    output_parts = []
    for p in clean_parts:
      part = p
      if any(eth in part for eth in found):
        # Ethnicity(s) found in this part
        for eth in found:
          if eth in part:
            # Remove ethnicity
            part = re.sub(eth, "", part)
  
      # Add part to output
      if len(part) > 2:
        output_parts.append(part)
  
    # Check if there was more than one general ethnicity. If so, the ad is multi-racial.
    if num > 1:
      found.append("multiracial")
  
    found = list(set(found))
  
    return (found, output_parts)