ugly python solution