n = len(C) for i in range(1, n+1): for k in range(0, i): if C[k][1] <= C[i][0]:n is the number of things in C. In Python the first index is 0 and the last index is len-1. If n is 3 there is a C[0], C[1] and C[2]. If you tried to get C[3] you will get a "list index out of range" error because there is no C[3].
When you do the loop "for i in range(1, n+1)" you try to look at C[n]. Remember that the possible index numbers range from 0 to len-1, so
C[len(C)]
is out of range.