1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to separate the string by specific symbols and write it to list in Python?

Discussão em 'Python' iniciado por Stack, Novembro 2, 2024 às 08:32.

  1. Stack

    Stack Membro Participativo

    I have the following string:

    my_string='11AB2AB33'

    I'd like to write this string in a list, so 'AB' is a single element of this list in the following way:

    ['1', '1', 'AB', '2', 'AB', '3', '3']


    I tried to do it by

    list(my_string)


    but the result wasn't what I expected:

    ['1', '1', 'A', 'B', '2', 'A', 'B', '3', '3']


    I also tried partition method:

    list(my_string.partition('AB'))


    and also didn't get expected result

    ['11', 'AB', '2AB33']

    Continue reading...

Compartilhe esta Página