Added Python implementation