In this post, we will take a look at how to compare two files using Python. I was tasked to compare 2 files and then list the differences between them using Python. Initially, I started with filecmp module, but even with the function parameter ‘ shallow’ set to false, the Boolean result was not enough. Sure, it can act as an indicator to take some action, but it will not list the differences. I was looking for something more visual, something like color coding and not like the git diff output, which is not very user-friendly. But, another Python internal module, difflib helped me to get the job done. Inside Difflib, HtmlDiff is what I was looking for. The differences were highlighted with 3 different colors and also the line numbers were indicated in a table to locate the differences. The results are quite self-explanatory and it is easier to explain the differences to other people. Code for generating the above difference table: Note: File1...
In this post, we are going to go over my notes while solving a coding question Today I am sharing my thoughts on the Cracking the coding interview question for chapter 3 Stacks and Queues, Q3.2 Below are my personal notes and working while solving the problem. I might be correct, wrong, or totally wrong, but I wanted to have a working copy of my train of thoughts while solving the problem. Notes section ************************************** what operations will the stack have? push,pop,getTop and isEmpty. Here all the operations will have a time complexity of O(1). while performing push operation we can maintain the min value. While performing the pop operation, how do we find the next min value? - When we are pushing the element, we can push the item and the min value, up to that item in the stack. In that way, we will have a track of min value up to a particular item when we start popping. For the pop operation, we can also have the min function work in O(1). push === 1. check ...