Ugly Python code