Your CRM exports client names with inconsistent casing, leading spaces, and underscores where spaces should be. When was the last time format_invoice_line got a name that looked like " acme_corp "?
Every single export. I fix them by hand before copying them into the invoice. That alone is ten minutes per month.
Python's string methods chain left-to-right. Three calls, no extra variables: strip() removes surrounding whitespace, lower() normalises case, replace("_", " ") swaps underscores for spaces. The cleanup that costs you ten minutes becomes one line:
raw = " acme_corp "
cleaned = raw.strip().lower().replace("_", " ")
print(cleaned) # acme corpWhy does order matter? Can I call .lower() before .strip()?
You can — both orders give the same result for stripping and lowering. But the habit of strip() first is cleaner: remove noise at the edges before you transform the content. The one order that matters is replace last — it acts on the already-normalised string.
So I can compose this with format_invoice_line from yesterday. Clean the name first, then format it.
That is the whole idea. Functions are Lego bricks. Clean, then format, then loop across six clients in Week 2:
def clean_client_name(raw: str) -> str:
result = raw.strip().lower().replace("_", " ")
print(f"Cleaned: {result}")
return resultTen minutes of monthly cleanup gone in three method calls.
The silent risk: lower() permanently downcases. If you need title case on the invoice — "Acme Corp" not "acme corp" — chain .title() at the end. Know which output the next function expects before you chain.
Three methods, one chain:
| Method | Does | Input → Output |
|---|---|---|
strip() | Remove leading/trailing whitespace | " Acme " → "Acme" |
lower() | Lowercase everything | "ACME" → "acme" |
replace(old, new) | Swap all occurrences | "acme_corp" → "acme corp" |
Each method returns a new string — chain them in one expression. Order matters only when one method's output affects another's input. strip() first is the safest default.
Your CRM exports client names with inconsistent casing, leading spaces, and underscores where spaces should be. When was the last time format_invoice_line got a name that looked like " acme_corp "?
Every single export. I fix them by hand before copying them into the invoice. That alone is ten minutes per month.
Python's string methods chain left-to-right. Three calls, no extra variables: strip() removes surrounding whitespace, lower() normalises case, replace("_", " ") swaps underscores for spaces. The cleanup that costs you ten minutes becomes one line:
raw = " acme_corp "
cleaned = raw.strip().lower().replace("_", " ")
print(cleaned) # acme corpWhy does order matter? Can I call .lower() before .strip()?
You can — both orders give the same result for stripping and lowering. But the habit of strip() first is cleaner: remove noise at the edges before you transform the content. The one order that matters is replace last — it acts on the already-normalised string.
So I can compose this with format_invoice_line from yesterday. Clean the name first, then format it.
That is the whole idea. Functions are Lego bricks. Clean, then format, then loop across six clients in Week 2:
def clean_client_name(raw: str) -> str:
result = raw.strip().lower().replace("_", " ")
print(f"Cleaned: {result}")
return resultTen minutes of monthly cleanup gone in three method calls.
The silent risk: lower() permanently downcases. If you need title case on the invoice — "Acme Corp" not "acme corp" — chain .title() at the end. Know which output the next function expects before you chain.
Three methods, one chain:
| Method | Does | Input → Output |
|---|---|---|
strip() | Remove leading/trailing whitespace | " Acme " → "Acme" |
lower() | Lowercase everything | "ACME" → "acme" |
replace(old, new) | Swap all occurrences | "acme_corp" → "acme corp" |
Each method returns a new string — chain them in one expression. Order matters only when one method's output affects another's input. strip() first is the safest default.
Carlos exports client names from his CRM every month and spends ten minutes fixing inconsistent casing, spaces, and underscores before building invoices. Write `clean_client_name(raw)` that strips whitespace, lowercases the string, and replaces underscores with spaces. For example, `clean_client_name(" Acme_Corp ")` should return `"acme corp"`.
Tap each step for scaffolded hints.
No blank-editor panic.