ochensati ochensati - 1 year ago 77
Python Question

"list indices must be integers, not list" with enumerate

I have this code

cNames = data["channelnames"]
goodChannels = [i for i,x in enumerate(cNames) if x!='Skipped']

I need the channel numbers later, but the cNames[goodChannels] throws the error "list indices must be integers, not list"

the list is made of integers. Is there a way to make this work correctly?

cNames[np.array(goodChannels)] does not work with the same error, so I am assuming that there is something else going on here.

Answer Source

You need another list comprehension:

data["channelnames"] = [cNames[i] for i in goodChannels]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download