When you export customers from your CRM, what do the names look like in the raw CSV?
format_metric worked clean, but the customer names from HubSpot come in as " Acme Corp " — extra spaces, random capitalisation, sometimes underscores instead of spaces. I'd have to clean them before I can use them in an investor email.
Three string methods chain together and solve exactly that problem. strip() removes leading and trailing whitespace. lower() normalises capitalisation. replace(" ", "_") swaps spaces for underscores — useful for IDs. They run left to right, each one feeding the next:
raw = " Acme Corp "
cleaned = raw.strip().lower().replace(" ", "_")
print(cleaned) # acme_corpWait — they chain directly? I don't need to store intermediate results?
Right. Each method returns a new string, so you can call the next method on it immediately. No intermediate variables needed. Here's the full function:
def clean_customer_name(raw: str) -> str:
result = raw.strip().lower().replace(" ", "_")
print(f"Cleaned: {result}")
return resultSo every name from any CRM export goes through this once and comes out normalised. I never have to TRIM() in Excel again.
TRIM() can't chain with LOWER() on the same cell without a nested nightmare. Python does it in one readable line.
I just replaced three nested Excel functions with a single method chain. That's genuinely better.
Watch out for replace() order — if you lower first and then replace, you won't accidentally miss uppercase spaces. Always strip before lower before replace. The sequence matters.
Strings in Python have built-in methods that return new strings. They chain left to right.
| Method | Effect | Example |
|---|---|---|
.strip() | Remove leading/trailing whitespace | " hi ".strip() → "hi" |
.lower() | Lowercase all characters | "Hi".lower() → "hi" |
.upper() | Uppercase all characters | "hi".upper() → "HI" |
.replace(a, b) | Swap every a for b | "hi hi".replace("hi", "x") → "x x" |
.split(sep) | Split into a list | "a,b".split(",") → ["a", "b"] |
Methods don't mutate in place — raw.strip() returns a new string; raw is unchanged. Always assign the result.
When you export customers from your CRM, what do the names look like in the raw CSV?
format_metric worked clean, but the customer names from HubSpot come in as " Acme Corp " — extra spaces, random capitalisation, sometimes underscores instead of spaces. I'd have to clean them before I can use them in an investor email.
Three string methods chain together and solve exactly that problem. strip() removes leading and trailing whitespace. lower() normalises capitalisation. replace(" ", "_") swaps spaces for underscores — useful for IDs. They run left to right, each one feeding the next:
raw = " Acme Corp "
cleaned = raw.strip().lower().replace(" ", "_")
print(cleaned) # acme_corpWait — they chain directly? I don't need to store intermediate results?
Right. Each method returns a new string, so you can call the next method on it immediately. No intermediate variables needed. Here's the full function:
def clean_customer_name(raw: str) -> str:
result = raw.strip().lower().replace(" ", "_")
print(f"Cleaned: {result}")
return resultSo every name from any CRM export goes through this once and comes out normalised. I never have to TRIM() in Excel again.
TRIM() can't chain with LOWER() on the same cell without a nested nightmare. Python does it in one readable line.
I just replaced three nested Excel functions with a single method chain. That's genuinely better.
Watch out for replace() order — if you lower first and then replace, you won't accidentally miss uppercase spaces. Always strip before lower before replace. The sequence matters.
Strings in Python have built-in methods that return new strings. They chain left to right.
| Method | Effect | Example |
|---|---|---|
.strip() | Remove leading/trailing whitespace | " hi ".strip() → "hi" |
.lower() | Lowercase all characters | "Hi".lower() → "hi" |
.upper() | Uppercase all characters | "hi".upper() → "HI" |
.replace(a, b) | Swap every a for b | "hi hi".replace("hi", "x") → "x x" |
.split(sep) | Split into a list | "a,b".split(",") → ["a", "b"] |
Methods don't mutate in place — raw.strip() returns a new string; raw is unchanged. Always assign the result.
Jordan exports customer names from HubSpot and they arrive inconsistently formatted — extra spaces, mixed capitalisation, spaces that should be underscores. Write `clean_customer_name(raw)` that strips whitespace, lowercases the name, and replaces spaces with underscores — for example, `clean_customer_name(" Acme Corp ")` should return `"acme_corp"`.
Tap each step for scaffolded hints.
No blank-editor panic.