Python List Iteration Using Dynamic Length

Viewed 46

I'm wanting to iterate over a loop in python but am not sure how to go about it.

channels = [1, 2]
for channel in channels:
    channel_filters = filters.channel(channel)

I need to end up like this:

channel_filters = filters.channel(1) | filters.channel(2) | filters.channel(3)

But need it to be dynamic with the length of the list.

Is anyone able to point me in the right direction on how best to achieve this?

1 Answers

I managed to resolve the issue with the answer shared by toppk.

channel_filters = 0;
channels = [-1, -2]
for channel in channels:
    temp_channel=abs(channel)
    channel_filters |= -abs(temp_channel)
    print(channel_filters)
Related