[Python] how do i split a string into equal parts recursively in python? [duplicate]

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

  1. Stack

    Stack Membro Participativo

    Example code

    import textwrap
    plaintext = '010040000130180083140130083190140000180190'
    print(plaintext + "\n")
    line = textwrap.wrap(plaintext, 3)
    print(line)


    My goal

    010040000130180083140130083190140000180190


    it should split into groups of 3:

    ['010', '040', '000', '130', '180', '083', '140', '130', '083', '190', '140', '000', '180', '190']


    then group three of these groups together:

    [(010, 040, 000), (130, 180, 083), (140, 130, 083), (190, 140, 000), (180, 190)]


    currently I can do the first part using

    textwrap.wrap(plaintext, 3)


    I cant figure out how to do the second part, though

    Continue reading...

Compartilhe esta Página