Idiomatic Python - Adapter Pattern

- Updated
#programming patterns #chemoinformatics

Writing idiomatic Python (also known as Pythonic code) is a skill that is greatly appreciated, since it improves both readability and maintainability of the code. Using a non-Pythonic ported from C++ I propose you how to adapt it using the Adapter design pattern.

The non-Pythonic API

RDKit is a widely used toolkit to work with molecules. With it you can compute properties, build molecules, fragment them, etc. The core data structures and algorithms are written in C++ and the Python wrappers are built automatically using Boost. So its API has C++ style. Here is a sample of RDKit code in Python: