How to split a 3-letter string

Asked

Viewed 558 times

-1

If anyone can help me I’m making a program in python 3 similar to those binary code translators, Base64 etc I’ve done what will turn words into code now I want to make the program that will turn the code into words so I have to divide the code that the user wrote 3 in 3 letters example G70H74L10M90 With the separation will stay like this G70 H74 L10 M90

1 answer

0


You can try importing the module re.

import re

# string de entrada
string = "G70H74L10M90"

# quebra a string, mas inclui strings vazias
lista = re.split("(\S{3})", string)

# remove strings vazias, deixa apenas o que interessa
final = list(filter(None, lista))

print(final)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.