Very unelegant solution in Python.