On 10/8/06, Roy Smith <[EMAIL PROTECTED]> wrote:
> "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > Certainly true, and it always gives me a hard time because I don't know
> > to which extend a regular expression nowadays might do the job because
> > of these extensions. It was so much easier back
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Certainly true, and it always gives me a hard time because I don't know
> to which extend a regular expression nowadays might do the job because
> of these extensions. It was so much easier back in the old times
What old times? I've been working
Fredrik Lundh wrote:
> it's slightly faster, but both your alternatives are about 10x slower
> than a straightforward:
> def balanced(txt):
> return txt.count("(") == txt.count(")")
I know, but if you read my post again you see that I have shown those
solutions to mark ")))(((" as bad expres
Mirco Wahab schrieb:
> Thus spoke Diez B. Roggisch (on 2006-10-08 10:49):
>> Certainly true, and it always gives me a hard time because I don't know
>> to which extend a regular expression nowadays might do the job because
>> of these extensions. It was so much easier back in the old times
>
>
Thus spoke Diez B. Roggisch (on 2006-10-08 10:49):
> Certainly true, and it always gives me a hard time because I don't know
> to which extend a regular expression nowadays might do the job because
> of these extensions. It was so much easier back in the old times
Right, in perl, this would be
[EMAIL PROTECTED] wrote:
> The dict solution looks better, but this may be faster:
it's slightly faster, but both your alternatives are about 10x slower
than a straightforward:
def balanced(txt):
return txt.count("(") == txt.count(")")
--
http://mail.python.org/mailman/listinfo/python
Tim Chase:
> It still doesn't solve the aforementioned problem
> of things like ')))(((' which is balanced, but psychotic. :)
This may solve the problem:
def balanced(txt):
d = {'(':1, ')':-1}
tot = 0
for c in txt:
tot += d.get(c, 0)
if tot < 0:
return Fal
On 8 Oct 2006 01:49:50 -0700, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> Even if it has - I'm not sure if it really does you good, for several
> reasons:
>
> - regexes - even enhanced ones - don't build trees. But that is what
> you ultimately want
>from an expression like sin(log(x))
>
>
hanumizzle wrote:
> On 7 Oct 2006 15:00:29 -0700, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> >
> > Chris wrote:
> > > I need a pattern that matches a string that has the same number of '('
> > > as ')':
> > > findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
> > > '((2x+2)si
> Why does it need to be a regex? There is a very simple and well-known
> algorithm which does what you want.
>
> Start with i=0. Walk the string one character at a time, incrementing i
> each time you see a '(', and decrementing it each time you see a ')'. At
> the end of the string, the co
In article <[EMAIL PROTECTED]>,
"Chris" <[EMAIL PROTECTED]> wrote:
> I need a pattern that matches a string that has the same number of '('
> as ')':
> findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
> '((2x+2)sin(x))', '(log(2)/log(5))' ]
> Can anybody help me out?
>
> Tha
On 7 Oct 2006 15:00:29 -0700, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
>
> Chris wrote:
> > I need a pattern that matches a string that has the same number of '('
> > as ')':
> > findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
> > '((2x+2)sin(x))', '(log(2)/log(5))' ]
> > C
Chris wrote:
> I need a pattern that matches a string that has the same number of '('
> as ')':
> findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
> '((2x+2)sin(x))', '(log(2)/log(5))' ]
> Can anybody help me out?
>
No, there is so such pattern. You will have to code up a func
Chris wrote:
> I need a pattern that matches a string that has the same number of '('
> as ')':
> findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
> '((2x+2)sin(x))', '(log(2)/log(5))' ]
> Can anybody help me out?
This is not possible with regular expressions - they can't "re
I need a pattern that matches a string that has the same number of '('
as ')':
findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
'((2x+2)sin(x))', '(log(2)/log(5))' ]
Can anybody help me out?
Thanks for any help!
--
http://mail.python.org/mailman/listinfo/python-list
15 matches
Mail list logo