Answer the question
In order to leave comments, you need to log in
How to divide letters in words into pairs?
I am writing a program for encrypting text in Python, the algorithm requires initially to divide the letters in the words of the text into pairs (Example: "Hello world" -> 'Pr', ''iv, 'et', 'm', 'ir'). Then we turn to the first element from the first pair, then to the second and so on, moving on to the second pair.
Answer the question
In order to leave comments, you need to log in
>>> import re
>>> re.findall('..?','Hello world')
['R', 'eve', 'em', 'm', 'ir']
s = "Привет мир"
[s[i:i+2] for i in range(0, len(s), 2)]
# ['Пр', 'ив', 'ет', ' м', 'ир']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question