Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Replace Multiple Spaces with a Single Space | Intermediate Regular Expressions
Python Regular Expressions

bookChallenge: Replace Multiple Spaces with a Single Space

Instructions: Clean Up Extra Spaces with Regex

Text data often contains inconsistent spacing, such as multiple consecutive spaces between words. You need to write a function that uses regex substitution to convert any sequence of multiple spaces into a single space, making the text cleaner and easier to process.

  • Use the re module for your solution;
  • Replace every sequence of two or more consecutive spaces with a single space;
  • Ensure the function returns the cleaned string.
Tarefa

Swipe to start coding

You are given a string that may contain extra spaces between words. Your task is to write a function that cleans up the text by replacing every sequence of two or more consecutive spaces with a single space. This will make the text easier to read and process. Use regular expressions to accomplish this.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 4
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you show me an example input and the expected output?

What should the function do if there are leading or trailing spaces?

Do you want the function to handle tabs or only spaces?

close

Awesome!

Completion rate improved to 6.67

bookChallenge: Replace Multiple Spaces with a Single Space

Deslize para mostrar o menu

Instructions: Clean Up Extra Spaces with Regex

Text data often contains inconsistent spacing, such as multiple consecutive spaces between words. You need to write a function that uses regex substitution to convert any sequence of multiple spaces into a single space, making the text cleaner and easier to process.

  • Use the re module for your solution;
  • Replace every sequence of two or more consecutive spaces with a single space;
  • Ensure the function returns the cleaned string.
Tarefa

Swipe to start coding

You are given a string that may contain extra spaces between words. Your task is to write a function that cleans up the text by replacing every sequence of two or more consecutive spaces with a single space. This will make the text easier to read and process. Use regular expressions to accomplish this.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 4
single

single

some-alt