<filename>001_rearrange_name/sample.py<gh_stars>0
import re


def rearrange_name(name: str) -> str:
    # Add a period '.' and space inside square bracket to capture period and space after a word
    result = re.search(r"^([\w \.-]*), ([\w \.-]*)", name)
    return name if not result else f"{result[2]} {result[1]}"

# Fictional name list which consists of
# - names in reversed order
# - single-word names
# - names with abbreviated middle names
# - names with one middle name
# - names with more than one middle name


name_list = [
    "<NAME>.",
    "Gabrielle",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>.",
    "<NAME>",
    "Raleigh",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "Pottinger, <NAME>.",
    "<NAME>",
    "<NAME>."
]

for name in name_list:
    print(rearrange_name(name))


# Expected result:

# <NAME>
# Gabrielle
# <NAME>
# <NAME>
# <NAME>
# <NAME>
# <NAME>
# Raleigh
# <NAME>
# <NAME>
# <NAME>
# <NAME>
# <NAME>
# <NAME>
# <NAME>
