bug fix in the python code; updated test cases; all results match now!!