0Pricing
NLP Academy · Lesson

Lowercasing and Stripping Whitespace

Your first normalization steps.

Lowercasing and Stripping Whitespace is a free NLP Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the NLP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Your First Two Steps

The simplest normalization is folding case and trimming spaces. Master these two and you already remove most of the noise that splits your word counts. ✨

Lowercasing in One Call

Python strings carry a built-in lower method. It returns a fresh copy with every letter folded to lowercase, leaving the original untouched.

text = 'The QUICK Fox'
print(text.lower())

Now They Match

Once both sides are lowercased, the case difference vanishes and the comparison finally returns True. That is the whole point of case folding.

print('Paris'.lower() == 'paris')

Trimming the Edges

The strip method removes whitespace from both ends of a string. Leading and trailing spaces, tabs, and newlines all disappear in one call.

messy = '  hello world  '
print(messy.strip())

One-Sided Trims

Sometimes you only want one edge cleaned. Use lstrip for the left side and rstrip for the right when you need that control.

print('  hi'.lstrip())
print('hi  '.rstrip())

Spaces in the Middle

Strip only touches the ends. To squash repeated spaces inside text, split on whitespace and rejoin, which collapses every gap to a single space.

text = 'too    many   spaces'
print(' '.join(text.split()))

Why Split Then Join

Calling split with no argument breaks on any run of whitespace and drops the empties. Rejoining with one space gives you clean, even spacing.

Chain Them Together

Because each method returns a string, you can chain them. Here you lowercase and strip a value in a single readable pipeline.

raw = '  CoddyKit  '
print(raw.lower().strip())

Strings Are Immutable

These methods never change the original; they hand back a new string. Always capture the result in a variable or you lose the cleaned value.

s = 'HELLO'
s.lower()
print(s)

Normalize a Whole List

Apply your two steps to every token at once with a comprehension. Now each word is lowercase and trimmed, ready for counting.

words = [' Cat ', 'DOG', 'Cat']
print([w.lower().strip() for w in words])

Counts Finally Agree

After folding case, the three messy entries for cat collapse into one matching token, so your frequency table tells the truth. 📊

Quick Check

Let's confirm how to clean spacing.

Recap

You learned to fold case with lower and trim edges with strip, then collapse inner gaps with split and join. Your tokens now match cleanly. Nice work! 🎉

Frequently asked questions

Is the “Lowercasing and Stripping Whitespace” lesson free?

Yes — the full text of “Lowercasing and Stripping Whitespace” is free to read here on the web, and the NLP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the NLP Academy course, upgrade to CoddyKit PRO.

What will I learn in “Lowercasing and Stripping Whitespace”?

Your first normalization steps. You practise NLP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start NLP Academy?

No prior experience is required. NLP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Lowercasing and Stripping Whitespace” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this NLP Academy lesson?

Yes. Every NLP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Why Case and Spacing Matter
  2. Lowercasing and Stripping Whitespace
  3. Stemming: Chopping to the Root
  4. Lemmatization: Smarter Base Forms
← Back to NLP Academy