0Pricing
NLP Academy · Lezione

Convertire in minuscolo e rimuovere gli spazi

I primi passaggi di normalizzazione

Convertire in minuscolo e rimuovere gli spazi è una lezione NLP Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento NLP Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso NLP Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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! 🎉

Domande Frequenti

La lezione «Convertire in minuscolo e rimuovere gli spazi» è gratuita?

Sì — il testo completo di «Convertire in minuscolo e rimuovere gli spazi» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso NLP Academy, passa a CoddyKit PRO. Il corso NLP Academy include 4 lezioni in totale.

Cosa imparerò in «Convertire in minuscolo e rimuovere gli spazi»?

I primi passaggi di normalizzazione Eserciti NLP Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare NLP Academy?

Non è richiesta alcuna esperienza precedente. NLP Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.

Quanto tempo richiede la lezione «Convertire in minuscolo e rimuovere gli spazi»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione NLP Academy?

Sì. Ogni lezione NLP Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Perché maiuscole e spaziatura contano
  2. Convertire in minuscolo e rimuovere gli spazi
  3. Stemming: ridurre alla radice
  4. Lemmatizzazione: forme base più intelligenti
← Torna a NLP Academy