Most complicated python code copy and paste