Re: count consecutive elements

2021-09-27 Thread Bischoop
I'd wish to have this challenge posted on my blog but because I suck in IT english, could you guys help me with decribing the task of what the code supposed to do? -- Thanks -- https://mail.python.org/mailman/listinfo/python-list

Re: count consecutive elements

2021-01-19 Thread Peter Otten
On 19/01/2021 10:42, Bischoop wrote: On 2021-01-19, Peter Otten <__pete...@web.de> wrote: 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 probl

Re: count consecutive elements

2021-01-19 Thread Bischoop
On 2021-01-19, Peter Otten <__pete...@web.de> wrote: > 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 happen

Re: count consecutive elements

2021-01-19 Thread Peter Otten
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

Re: count consecutive elements

2021-01-18 Thread Bischoop
On 2021-01-14, Stefan Ram wrote: > > If you want to know why, maybe you should insert print > statements to see the values of critical variables and > expression, especially in loops. > > Then compare the printed values with your expectations. > > Also, decompose into meaningful functio

Re: count consecutive elements

2021-01-17 Thread Peter Otten
On 17/01/2021 02:15, Dan Stromberg wrote: IMO a good set of tests is much more important than type annotations ;) def get_longest(string: str) -> typing.Tuple[int, typing.List[str]]: """Get the longest run of a single consecutive character.""" May I ask why you artificially limit th

Re: count consecutive elements

2021-01-16 Thread Dan Stromberg
On Thu, Jan 14, 2021 at 2:01 PM Wolfram Hinderer via Python-list < python-list@python.org> wrote: > Am 13.01.2021 um 22:20 schrieb Bischoop: > > I want to to display a number or an alphabet which appears mostly > > consecutive in a given string or numbers or both > > Examples > > s= ' aabskaaabad

Re: count consecutive elements

2021-01-15 Thread Tim Chase
On 2021-01-16 03:32, Bischoop wrote: >> The OP didn't specify what should happen in that case, so it would >> need some clarification. > > In that case maybe good solution would be to return three of them? That's the solution I chose in my initial reply, you get a tuple back of ([list of longest

Re: count consecutive elements

2021-01-15 Thread Bischoop
On 2021-01-14, Tim Chase wrote: > > seems to only return one value so seems to get odd results if I > specify something like > > get_longest("aaabcccbbb") > > which at least here tells me that "c" is the longest run, even though > aaa, bbb, and ccc are all runs of length 3. The OP didn't specif

Re: count consecutive elements

2021-01-14 Thread Wolfram Hinderer via Python-list
Am 13.01.2021 um 22:20 schrieb Bischoop: I want to to display a number or an alphabet which appears mostly consecutive in a given string or numbers or both Examples s= ' aabskaaabad' output: c # c appears 4 consecutive times 8bbakebaoa output: b #b appears 2 consecutive times You can

Re: count consecutive elements

2021-01-14 Thread Bischoop
On 2021-01-13, Bischoop wrote: I know what was wrong: > m = s.index(i) I forgot that m will return first index of i. So tried that way but still getting out of index although I that that I'm making sure not to get out of index. s = 'aabskaaabadh' c = 0 t = list(set(s)) # list

Re: count consecutive elements

2021-01-14 Thread Dan Stromberg
On Wed, Jan 13, 2021 at 6:20 PM Dan Stromberg wrote: > On Wed, Jan 13, 2021 at 5:59 PM Tim Chase > wrote: > >> On 2021-01-13 21:20, Bischoop wrote: >> > I want to to display a number or an alphabet which appears mostly >> > consecutive in a given string or numbers or both >> > Examples >> > s=

Re: count consecutive elements

2021-01-13 Thread Tim Chase
On 2021-01-13 18:20, Dan Stromberg wrote: > I'm kind of partial to: > > import collections > import typing > > > def get_longest(string: str) -> typing.Tuple[int, str]: > """Get the longest run of a single consecutive character.""" > dict_: typing.DefaultDict[str, int] = > collections.de

Re: count consecutive elements

2021-01-13 Thread Dan Stromberg
On Wed, Jan 13, 2021 at 5:59 PM Tim Chase wrote: > On 2021-01-13 21:20, Bischoop wrote: > > I want to to display a number or an alphabet which appears mostly > > consecutive in a given string or numbers or both > > Examples > > s= ' aabskaaabad' > > output: c > > # c appears 4 consecutive ti

Re: count consecutive elements

2021-01-13 Thread Tim Chase
On 2021-01-13 21:20, Bischoop wrote: > I want to to display a number or an alphabet which appears mostly > consecutive in a given string or numbers or both > Examples > s= ' aabskaaabad' > output: c > # c appears 4 consecutive times > 8bbakebaoa > output: b > #b appears 2 consecutive times I

Re: count consecutive elements

2021-01-13 Thread Bischoop
On 2021-01-13, Bischoop wrote: > t = set(s) # set of characters in s I have this one changed to: t= list(set(s)) -- https://mail.python.org/mailman/listinfo/python-list

count consecutive elements

2021-01-13 Thread Bischoop
I want to to display a number or an alphabet which appears mostly consecutive in a given string or numbers or both Examples s= ' aabskaaabad' output: c # c appears 4 consecutive times 8bbakebaoa output: b #b appears 2 consecutive times I thought about set the string then and for each element