I have the following text: "ola sou o Allan"
I would like to have this text divided by eg 2 in 2 chars. How can I do this?
I have the following text: "ola sou o Allan"
I would like to have this text divided by eg 2 in 2 chars. How can I do this?
So:
texto = "ola sou o Allan"
lista = [texto[i:i+2] for i in range(0, len(texto), 2)]
Running:
>>> texto = "ola sou o Allan"
>>> lista = [texto[i:i+2] for i in range(0, len(texto), 2)]
>>> lista
['ol', 'a ', 'so', 'u ', 'o ', 'Al', 'la', 'n']
According to the English response, 2
may be variable:
>>> n = 2
>>> texto = "ola sou o Allan"
>>> lista = [texto[i:i+n] for i in range(0, len(texto), n)]
>>> lista
['ol', 'a ', 'so', 'u ', 'o ', 'Al', 'la', 'n']