Friday, 24 January 2014

Except This! (Week 3)

   Exceptions are the bane of every student's programming life. Until this week we only knew just a handful of them which would usually come up every time I ran a code (IndentationError, SyntaxError being the most common ones). Now, we can even create them! By learning how to create them we also started delving into the concepts of inheritance and OOP. This is when the fun begins!

   I also would like to state how I implemented the Stack and Queue classes for the lab assignment. I basically used a binary tree consisting of duples as nodes for the Stack class and used linked list to implement the Queue class which resulted in better performance from the code. I also used an integer to solve the balanced parenthesis problem we discussed in class which was more efficient in space usage than a stack.

If you want more information about the implementations I would gladly send you the code! Til next time!

Yo check this sudoku solver written in python!


  1. I'd love to see your queue efficiency solution implemented! Sounds neat!

    I thought of using an integer, too, because it's obviously much simpler. But note that it only finds balance, not proper order, so it will say ')(' is okay when it's actually poor syntax!

  2. I need to check my archive for queue class, can post it in couple of days.
    Meanwhile here is the code for the balance problem, I just whipped it up so if there are any problems let me know! It doesn't have the problem with ')(' since it never drops to lower than 0.

    def balanced(_str):
    balance = 0
    for _char in _str:
    if _char == '(':
    balance += 1
    if _char == ')':
    balance -= 1
    if balance < 0:
    return False
    return balance == 0

    1. Formatting sucks at blogspot so here is a better version