nested if in for loop python