On 08/25/10 14:46, Jed wrote:
I would like to split the string 'churro' into a list containing: 'ch','u','rr','o'
Dirt simple, straightforward, easily generalized solution: def sp_split(s): n,i,ret = len(s), 0, [] while i < n: s2 = s[i:i+2] if s2 in ('ch', 'll', 'rr'): ret.append(s2) i += 2 else: ret.append(s[i]) i += 1 return ret print(sp_split('churro')) #'ch', 'u', 'rr', 'o'] -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list