'Is there a way to avoid using a counter in nested for statement?

index = 0
for i in range(16):
    if flags >> i & 1:
        decoded_matrix[0][i] = np.frombuffer(data, dtype=np.dtype(np.float32).newbyteorder(">"))[index]
            index += 1

Is there a way to avoid the "index" variable? It increments every time flags >> i & 1 for numbers 1 - 16.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source