Re: Detecting repeated subsequences of identical items

2016-04-22 Thread Steven D'Aprano
On Fri, 22 Apr 2016 12:12 am, Chris Angelico wrote: > On Fri, Apr 22, 2016 at 12:01 AM, Oscar Benjamin > wrote: >> In the recursive stack overflow case what you'll usually have is >> >> 1) A few frames leading up to the start of recursion >> 2) A long repetitive

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Chris Angelico
On Fri, Apr 22, 2016 at 12:30 AM, Oscar Benjamin wrote: > On 21 April 2016 at 15:12, Chris Angelico wrote: >> On Fri, Apr 22, 2016 at 12:01 AM, Oscar Benjamin >> wrote: >>> In the recursive stack overflow case what you'll

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Oscar Benjamin
On 21 April 2016 at 15:12, Chris Angelico wrote: > On Fri, Apr 22, 2016 at 12:01 AM, Oscar Benjamin > wrote: >> In the recursive stack overflow case what you'll usually have is >> >> 1) A few frames leading up to the start of recursion >> 2) A long

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Chris Angelico
On Fri, Apr 22, 2016 at 12:01 AM, Oscar Benjamin wrote: > In the recursive stack overflow case what you'll usually have is > > 1) A few frames leading up to the start of recursion > 2) A long repetitive sequence of frames > 3) A few frames at the end showing how the

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Oscar Benjamin
On 21 April 2016 at 13:15, Steven D'Aprano wrote: > On Thu, 21 Apr 2016 06:53 pm, Oscar Benjamin wrote: > >> On 21 April 2016 at 04:07, Steven D'Aprano wrote: >>> I want to group repeated items in a sequence. For example, I can group >>> repeated

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Steven D'Aprano
On Thu, 21 Apr 2016 06:53 pm, Oscar Benjamin wrote: > On 21 April 2016 at 04:07, Steven D'Aprano wrote: >> I want to group repeated items in a sequence. For example, I can group >> repeated sequences of a single item at a time using groupby: >> >> >> from itertools import

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Nobody
On Thu, 21 Apr 2016 18:05:40 +1000, Steven D'Aprano wrote: > The specific problem I am trying to solve is that I have a sequence of > strings (in this case, error messages from a Python traceback) and I'm > looking for repeated groups that may indicate mutually recursive calls. E.g. > suppose

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Serhiy Storchaka
On 21.04.16 06:07, Steven D'Aprano wrote: Now I want to group subsequences. For example, I have: "ABCABCABCDEABCDEFABCABCABCB" and I want to group it into repeating subsequences. [...] How can I do this? Does this problem have a standard name and/or solution? This is a part of lossless

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Oscar Benjamin
On 21 April 2016 at 04:07, Steven D'Aprano wrote: > I want to group repeated items in a sequence. For example, I can group > repeated sequences of a single item at a time using groupby: > > > from itertools import groupby > for key, group in groupby("BBCDDEEE"): >

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Steven D'Aprano
On Thursday 21 April 2016 16:35, Michael Selik wrote: > On Wed, Apr 20, 2016 at 11:11 PM Steven D'Aprano > wrote: > >> I want to group [repeated] subsequences. For example, I have: >> "ABCABCABCDEABCDEFABCABCABCB" >> and I want to group it into repeating subsequences. I can

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Alain Ketterlin
Steven D'Aprano writes: > I want to group repeated items in a sequence. For example, I can group > repeated sequences of a single item at a time using groupby: [...] > Now I want to group subsequences. For example, I have: > > "ABCABCABCDEABCDEFABCABCABCB" > > and I want to

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Michael Selik
On Thu, Apr 21, 2016 at 2:55 AM Vlastimil Brom wrote: > 2016-04-21 5:07 GMT+02:00 Steven D'Aprano : > > I want to group subsequences. > > "ABCABCABCDEABCDEFABCABCABCB" > > ABC ABC ABCDE ABCDE F ABC ABC ABC B > > or: > > ABC ABC ABC D E A B C D E F

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Vlastimil Brom
2016-04-21 5:07 GMT+02:00 Steven D'Aprano : > I want to group repeated items in a sequence. For example, I can group > repeated sequences of a single item at a time using groupby: > > > from itertools import groupby > for key, group in groupby("BBCDDEEE"): > group

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Michael Selik
On Thu, Apr 21, 2016 at 2:35 AM Michael Selik wrote: > On Wed, Apr 20, 2016 at 11:11 PM Steven D'Aprano > wrote: > >> I want to group [repeated] subsequences. For example, I have: >> "ABCABCABCDEABCDEFABCABCABCB" >> and I want to group it into

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Michael Selik
On Wed, Apr 20, 2016 at 11:11 PM Steven D'Aprano wrote: > I want to group [repeated] subsequences. For example, I have: > "ABCABCABCDEABCDEFABCABCABCB" > and I want to group it into repeating subsequences. I can see two > ways... How can I do this? Does this problem have a

Re: Detecting repeated subsequences of identical items

2016-04-20 Thread Chris Angelico
On Thu, Apr 21, 2016 at 1:07 PM, Steven D'Aprano wrote: > Now I want to group subsequences. For example, I have: > > "ABCABCABCDEABCDEFABCABCABCB" > > and I want to group it into repeating subsequences. I can see two ways to > group it: > > ABC ABC ABCDE ABCDE F ABC ABC ABC B

Re: Detecting repeated subsequences of identical items

2016-04-20 Thread Ethan Furman
On 04/20/2016 08:57 PM, Ethan Furman wrote: > [snip same pattern as Steven wrote] Nevermind. It's obviously time for me to go to bed. :/ -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list

Re: Detecting repeated subsequences of identical items

2016-04-20 Thread Ethan Furman
On 04/20/2016 08:07 PM, Steven D'Aprano wrote: Now I want to group subsequences. For example, I have: "ABCABCABCDEABCDEFABCABCABCB" and I want to group it into repeating subsequences. I can see two ways to group it: ABC ABC ABCDE ABCDE F ABC ABC ABC B giving counts: (ABC) count = 2 (ABCDE)

Detecting repeated subsequences of identical items

2016-04-20 Thread Steven D'Aprano
I want to group repeated items in a sequence. For example, I can group repeated sequences of a single item at a time using groupby: from itertools import groupby for key, group in groupby("BBCDDEEE"): group = list(group) print(key, "count =", len(group)) outputs: A count = 4 B