Implementation in Python