Python Notes: Global Interpreter Lock
Python uses reference count for memory management. Each objects in python has a reference count variables that keep track of the number of reference to the object. When the reference count goes back to 0, Python would release this object from memory.
Python Notes: Decorator
By definition, a decorator is a function that takes another function and extends the behavior of the latter function without explicitly modifying it. Built-in decorators such as @staticmethod, @classmethod, and @property work in the same way.
Python Notes: function as first class object
Per history of python blog, everything in python are first class objects, that means all objects that could be named in the language (e.g., integers, strings, functions, classes, modules, methods, etc.) to have equal status. Th:at is, they can be assigned to variables, placed in lists, stored in dictionaries, passed as arguments, and so forth..
Python Notes: Iterator, Generator and Co-routine
Iteration Python support iteration, for example, iterating over a list: for elem in [1, 2, 3]: print elem Iterating over a dict: for key in {'Google': 'G', 'Yahoo': 'Y', 'Microsoft': 'M'}: print key Iterating over a file: with open('path/to/file.csv', 'r') as file:...
Python Notes: Context management
Python supports context management. Which often used when handling resources, for example, file, network connection. With statement helps make sure the resources are cleaned up or released. There are two major functions for context management: __enter__ and __exit__.
Python Notes: Closure
The following is an example of python closure. def outer_function(outter_arg): closure_var = outter_arg def inner_function(inner_arg): print("{} {}".format(closure_var, inner_arg)) return inner_function # Usage of a python closure closure_func = outer_function("X")...
Machine Learning: Simple Linear Regression
Let's first take a look at simple linear regression. First let's start with an open question: imagine you can get all the information you need, how do you predict the selling price of a house? I believe you might consider the following factors: House sizeHouse...
Sliding Window: Minimal Window of Array
Sliding window is a common approach in solving algorithm problems, it has a few elements: Window start and end. Status of elements in the window. Window extends to the right according to the status. Window shrinks to the right according to the status. Window stops moving at certain condition.
Maximum Size Subarray Sum Equals K
Java solution to the Maximum Size Subarray Sum Equals K problem.
Maximum Product Subarray
Solution to the Maximum Product Subarray problem.