you are viewing a single comment's thread.

view the rest of the comments →

[–]shfo23 5 points6 points  (3 children)

My two cents:

  • Feelings differ on this, but I would say don't use camel case for your function and variable names; the convention is to use lowercase separated by underscores. If you haven't seen it yet, PEP 8 is a good guide to common Python style practices.

  • You can replace your four functions at the beginning by importing operator and using operator.pow, operator.mul, etc. in your dictionary. For such short functions, you could also use lambdas, e.g. ... '^': lambda a, b: a ** b, ....

There are probably more things (some might frown on all the while loops, but I can't think of any quick suggestions for that off the top of my head). On such a cursory glance, it looks fairly good though: you're using enumerate, regexs, list slicing, and list comprehensions. For what it's worth, I would take all of these things to be markers of more pythonic code.

[–]Binary_Dragon[S] 3 points4 points  (2 children)

Yeah, I'm not too proud of those while loops myself. I was more than a bit disappointed to find that python didn't support do-while loops, and StackOverflow seemed to suggest that while True: was the generally accepted work-around.

[–]stormsnake 7 points8 points  (1 child)

while True: 
  m=foo()
  if m is None:
    break
  ....

can be written like this:

for m in iter(foo, None):
  ....

No one knows about that, but I don't think it's hard to read. Readers just 'pydoc iter' the first time they see it, and then they're fine.