Avatar ·

Replacing double space with single space in a string

📁 string, Advanced Python Topics, work

I have a string:

str = 'A l a  m a  k o t a'

As you can see in the string, between letters of one word I have one space, between words two spaces.
I want to convert the string to:

'Ala ma kota'

I tried to solve it like this, but failed:

First I replace double spaces with '`':

for i in range(len(str)-1):    if str[i] == ' ' and 

                    
                
Avatar ·

I'll try to supplement @ext's answer.

async/await is an optimization, i.e. it should absolutely not be used where everything works fine as is. Because it complicates the program execution logic and brings a lot of overhead. Because if you decide to use asynchronous functionality - be kind enough to use ONLY libraries that support it.

Executing asynchronous code is similar to executing multithreaded code on a single-core processor. There are also several tasks that can be executed simultaneously and there is an execution context for each task. However, with multithreading, the processor itself decides by timer when to switch context and start executing another task.

The asynchronous approach assumes that the application itself sets a special

Log in to leave an answer

Blogs