14
Lesson 21 of 44

Text processing

Take your knowledge of strings to the next level. In this lesson you will learn how to loop over and transform characters with ord and chr, how to split, join and search text, how to format tables and numbers, and how to clean and normalize strings. You will solve classic text problems such as palindromes, ciphers, acronyms or compression, with practical exercises.

  • 5 theory articles
  • 9 practice exercises
Start lesson

Fundamentals concepts 5

Looping over and transforming characters

A string is a sequence of characters, and many text problems are solved by going through it character by character and building a…

Theory
Read more

Splitting, joining and searching text

A large part of working with text consists of cutting it into pieces, joining them again and locating specific parts. Python has…

Theory
Read more

Formatting text and numbers

f-strings accept a format specifier after a colon, which controls the width, the alignment and the decimals. With it you can…

Theory
Read more

Cleaning and normalizing text

The texts that people write arrive messy: mixed capitals, extra spaces, accents, signs. Normalizing is transforming them into a…

Theory
Read more

Typical text patterns and common mistakes

Almost every text problem is solved by combining a few patterns. Recognizing them saves you a lot of time.

Theory
Read more

Practice exercises 9

Acronym

Create a Python program that forms the acronym of a sentence with the first letter of each word.

Exercise Easy
Solve it

Count vowels

Create a Python program that counts how many times each vowel appears in a text.

Exercise Easy
Solve it

Split user and domain

Create a Python program that splits an email address into user and domain with the partition method.

Exercise Easy
Solve it

Normalize names

Create a Python program that cleans up a carelessly written name.

Exercise Easy
Solve it

Palindromes

Create a Python program that checks whether a sentence is a palindrome, that is, whether it reads the same from left to right as…

Exercise Medium
Solve it

Caesar cipher

Create a Python program that encrypts a text with the Caesar cipher, which shifts each letter a fixed number of positions in the…

Exercise Medium
Solve it

Text compression

Create a Python program that compresses a text by indicating how many times each letter is repeated consecutively.

Exercise Medium
Solve it

Validate password

Create a Python program that checks whether a password meets some rules and says which ones it breaks.

Exercise Medium
Solve it

Shopping receipt

Create a Python program that prints a receipt with well-aligned columns using f-string formatting.

Exercise Medium
Solve it