[Python] Replace repeated characters with the number of times repeated

Discussão em 'Python' iniciado por Stack, Março 2, 2025.

  1. Stack

    Stack Membro Participativo

    I want to replace repeated characters in a string with the number of times repeated and the character itself: e.g.

    bo$bbo$ooo!


    becomes

    bo$2bo$3o!


    It will only apply to b and o. Every solution I have come up with hasn't worked and seems very complicated compared to the task and ends up not working, is there any quick way to do this?

    Continue reading...

Compartilhe esta Página