Interfaces in Python : DuckTyping + ABCs





Python sorted, itemgetter, stdin

I find it interesting how implementing a simple algorithm can teach you so many new things.

I was recently implementing the fractional knapsack problem

The interesting was – during implementation I got to learn some interesting things about Python.




Python Class Attributes

I recently came across this interesting article on class attributes v/s instance attributes in Python.




Factory Pattern in Python

I recently used the factory Pattern in Python.

It was a little surprising to me comparing typical usage of this pattern in C# v/s Python.

In particular, in C# you’s typically have an Interface defining the methods and then provide an implementation of these methods in the concrete classes.

In Python, there is no interface – In the example above I embed a static  method in the base  to select the appropriate derived class.