Re: Python code for testing well parenthesized expression

2009-07-14 Thread Adrian Dziubek
> Don't you want to just test that the number of "("s equals the number of
> ")"s or am I missing the point?
I had this idea too, but there is additional requirement that any
beginning must have greater or equal number of '(' than ')'.
--
Adrian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python code for testing well parenthesized expression

2009-07-14 Thread Adrian Dziubek
Strings are immutable, so your method of slicing one letter at time
will be building lots of them. That shouldn't hurt you here, but it
will when you hit a bigger problem. In the i() there should be "return
op == 0" on the end.

def well(expr):
  mapping = {'(':1, ')':-1}
  count = 0
  for s in expr:
if s in mapping:
  count += mapping[s]
if s < 0:
  return False
  return count == 0

def test_well():
  examples = [
('zx4er(1(er(Yy)ol)ol)ik', True),
('x(x)x(x(x)xx(xx(x)x(x(x)xx)())x(x(x)xx)()x)()',
True),
('a(ty(y(y(bn)))lokl)kl', True),
('xc(er(tgy(rf(yh)()uj)ki))', True),
('e', True),
('rf(tgt)juj)jkik(jun)', False),
('zx(4er(1(er(Yy)ol)ol)ik', False),
  ]
  for expr, expected in examples:
assert well(expr) == expected
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: older pythons

2009-07-09 Thread Adrian Dziubek
The recommended Debian way is update-alternatives. I find it a bit
unintuitive, so I have to read through the documentation every time I
use it, but it should be able link a chosen version of python to /usr/
bin/python. I don't know if it's set up by default, I have only one
version installed.
--
Adrian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: modifying a list element from a function

2009-03-27 Thread Adrian Dziubek
Could you explain your high level goal for this? It looks like a very
wicked way of doing things. Have You tried to read the list methods'
documentation? Maybe there you find something you need (like
list.index)?
-- 
Adrian
--
http://mail.python.org/mailman/listinfo/python-list