CopeAleph CopeAleph - 1 year ago 138
Python Question

Splitting messages in python

tfi = '''
aardvark
albatross
alligator
alpaca
ant
anteater
antelope
'''

print(tfi)


Ok so, this is just a small section of the tfi string, but how do I make the code print this out in sections decided by amount of characters.

pseudo:

print tfi (3 chars):
returns:
'aar'
(new message)
'dva'


and so on...

Answer Source

Try this:

def tfi(my_string, dif):
    for i in range(0, len(my_string), dif):
        print(my_string[i:i+dif])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download