Not quite finished Python-only solution