count consecutive elements

Peter Otten __peter__ at web.de
Tue Jan 19 03:51:16 EST 2021


On 19/01/2021 04:45, Bischoop wrote:

> I sat to it again and solved it.

Congratulations!

 > lil = tuple(set(s)) # list of characters in s
 >
 > li=[0,0,0,0,0,0]  # list for counted repeats

I see a minor problem here. What happens if s contains more than len(li) 
characters?

> import timeit

Since you seem interested in performance: imagine that the input is a 
very long string. Let's call the length N.

How often do you iterate over its characters?
How often does Tim's solution?



More information about the Python-list mailing list