naive string question

Michał Kurowski mkur at poczta.gazeta.pl
Tue Mar 4 19:41:18 EST 2003


Hi,

I'm looking for a fast and elegant way of mapping a string to a list
based on changes in the string (something like 'aaa-ab-a-bbbaa').

So far I've got this:

b= []
for i in range(1, len(a)):
    if a[i] != a[i-1]:
        b.append((i, a[i-1]))

It's truly the first thing that came to my mind.
(Perhaps a bit influenced by not so good performance-wise 
experience with functional programming tools ;-).

Something better highly appreciated.

Cheers,

-- 
Michal Kurowski
<mkur at poczta.gazeta.pl>




More information about the Python-list mailing list