[Python] How can I make multiple replacements in a string using a dictionary?

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

  1. Stack

    Stack Membro Participativo

    Suppose we have:

    d = {
    'Спорт':'Досуг',
    'russianA':'englishA'
    }

    s = 'Спорт russianA'


    How can I replace each appearance within s of any of d's keys, with the corresponding value (in this case, the result would be 'Досуг englishA')?

    Continue reading...

Compartilhe esta Página