I'm wondering what the following is evaluating to on each iteration, I've checked the internet but can't find any definite answers
And also if there's anymore efficient ways to do it.
for i in range(0, len(c)):
if i & True:
pass
True has an integer value of 1 in Python, so when the loop iterates an integer i from 0 to the length of c and performs bitwise-and on i and 1, it effectively checks if i is an odd number and if so, executes the pass statement (where I believe there are more code in your real code).
As for a more efficient way to do it, instead of generating all the numbers between 0 and the length of c and filtering out even numbers, you can use the step parameter of the range function to generate the desired sequence of odd numbers in the first place:
for i in range(1, len(c), 2):
pass
&is a bitwise operator.if i & True:is equivalent to writingif i:. In the greater context of the loop,iwill evaluate to True for non-zero, so you could rewrite the loop asfor i in range(1, len(c)):i and True.&is a bit-wise operator, not a logical operator.