Suppose you have a sequence s , a string  for say, for instance this one :

spppammmmegggssss

We want to split s into the following parts :

['s', 'ppp', 'a', 'mmmm', 'e', 'ggg', 'ssss']

ie each part is a single repeated character word.

What is the pythonic way to answer this question?

A naive solution would be the following :


# -------------------------------
z='spppammmmegggssss'

zz=[]
while z:
    k=1
    while z[:k]==k*z[0]:
        k+=1
    zz+=[z[:k-1]]
    z=z[k-1:]

print zz
# -------------------------------


but I guess this code is not very idiomatic :(
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to