ich habe folgende zwei Strings:
Code: Alles auswählen
a = "AAAAAAAAAAAAAA"
b = "BBBBBBBBBBB"
Code: Alles auswählen
AAA
AAA
AAA
AAA
AAB
BBB
BBB
BBB
B
Viele Grüße
Code: Alles auswählen
a = "AAAAAAAAAAAAAA"
b = "BBBBBBBBBBB"
Code: Alles auswählen
AAA
AAA
AAA
AAA
AAB
BBB
BBB
BBB
B
Code: Alles auswählen
>>> a = "AAAAAAAAAAAAAA"
>>> b = "BBBBBBBBBBBBBBBBBBBB"
>>> from textwrap import fill
>>> print fill(a+b,3)
AAA
AAA
AAA
AAA
AAB
BBB
BBB
BBB
BBB
BBB
BBB
B
Code: Alles auswählen
def triple_generator(iterable):
while iterable:
yield iterable[0:3]
iterable = iterable[3:]
Code: Alles auswählen
In [29]: x = triple_generator(a+b)
In [30]: for c in x:
....: print c
....:
....:
AAA
AAA
AAA
AAA
AAB
BBB
BBB
BBB
B
Code: Alles auswählen
import re
a = "AAAAAAAAAAAAAA"
b = "BBBBBBBBBBB"
print re.sub("(...)", "\\1\n", a + b)