Re: finding indices in a sequence of parentheses

2005-05-30 Thread Steven Bethard
Raymond Hettinger wrote: > [Steven Bethard] > >>>I have a list of strings that looks something like: >>>lst = ['0', '0', '(*)', 'O', '(*', '*', '(*', '*))', '((*', '*)', '*)'] > > . . . > >>>I want the indices: >>>(2, 2), (4, 7), (6, 7), (8, 9) and (8, 10) > > opener_stack = [] > for i, elem i

Re: finding indices in a sequence of parentheses

2005-05-30 Thread tiissa
Peter Otten wrote: > I think no amount of testing will give these strange people confidence. > "Proof" is the magic word here. Some would maybe be satisfied if your tests cover the whole set of input. When that's possible, that may be useless. But that's not a matter to bother them with. ;) (An

Re: finding indices in a sequence of parentheses

2005-05-30 Thread Peter Otten
tiissa wrote: > Not tested but confident is an oxymoron for mathemtaticians. I think no amount of testing will give these strange people confidence. "Proof" is the magic word here. Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: finding indices in a sequence of parentheses

2005-05-30 Thread tiissa
Peter Otten wrote: > tiissa wrote: >>Disclaimer: not tested further than example above (but confident). > > Not tested but confident should be an oxymoron for a programmer. Not tested but confident is an oxymoron for mathemtaticians. Programmers know better than that, they leave bugs in their cod

Re: finding indices in a sequence of parentheses

2005-05-29 Thread Peter Otten
tiissa wrote: > Steven Bethard wrote: >> (2) Does anyone see an easier/clearer/simpler[1] way of doing this? > > I'd personnally extract the parenthesis then zip the lists of indices. > In short: > > >>> def indices(mylist): > ... lopen=reduce(list.__add__, [[i]*s.count('(') for i,s in >

Re: finding indices in a sequence of parentheses

2005-05-29 Thread Raymond Hettinger
[Steven Bethard] >> I have a list of strings that looks something like: >> lst = ['0', '0', '(*)', 'O', '(*', '*', '(*', '*))', '((*', '*)', '*)'] . . . >> I want the indices: >> (2, 2), (4, 7), (6, 7), (8, 9) and (8, 10) opener_stack = [] for i, elem in enumerate(lst): for c in elem:

Re: finding indices in a sequence of parentheses

2005-05-29 Thread Steven Bethard
tiissa wrote: > I'd personnally extract the parenthesis then zip the lists of indices. > In short: > > >>> def indices(mylist): > ... lopen=reduce(list.__add__, [[i]*s.count('(') for i,s in > enumerate(mylist)],[]) > ... lclose=reduce(list.__add__, [[i]*s.count(')') for i,s in > enume

Re: finding indices in a sequence of parentheses

2005-05-29 Thread tiissa
Steven Bethard wrote: > (2) Does anyone see an easier/clearer/simpler[1] way of doing this? I'd personnally extract the parenthesis then zip the lists of indices. In short: >>> def indices(mylist): ... lopen=reduce(list.__add__, [[i]*s.count('(') for i,s in enumerate(mylist)],[]) ...

finding indices in a sequence of parentheses

2005-05-29 Thread Steven Bethard
I have a list of strings that looks something like: lst = ['0', '0', '(*)', 'O', '(*', '*', '(*', '*))', '((*', '*)', '*)'] The parentheses in the labels indicate where an "annotation" starts and ends. So for example, the label '(*)' at index 2 of the list means that I have an annotation at (2