with the function:
you put every letter from the string in a list,
I want to put each 2 letters in a list
so If I had the string: ThisIsATestt

I want to get a list:

(There will never be a letter alone, so you don't have to think about that)

try this:

g = "ThisIsATestt"
count = 0
tmp_s = ""
l = []

for i in range( 0, len( g ) + 1, 2 ):
    if i != 0:
        while count < i:
            tmp_s += g[ count ]
            count += 1
        l += [ tmp_s ]
        tmp_s = ""

print l

note that you can specify the length of each segment by simply changing the increment value, i.e '2' in the range function
hope that helps. if not i'll post details on my solution :)

Edited 7 Years Ago by masterofpuppets: n/a

you can use list comprehensions

g = "ThisIsATestt"
print [g[i:i+2] for i in range(0,len(g),2)]

Edited 7 Years Ago by jice: n/a

This question has already been answered. Start a new discussion instead.