I will try to describe the core of my problem: I have a list of signals, each with its own alias, and a dataset of many entries of alias, value, and the quality of the value (the qualitycan be 0, 1, or 2). i am trying to loop through the signals, find its alias in the dataset, and update a counter of how many times each signals has been written with a given quality. I have built a dictionary
dati = {'signals': [signal1, signal2, ...], 'alias': [alias1, alias2, ...], 'nGOOD': [0, 0, ...], 'nBAD': [0, 0, ...], 'nFREEZE': [0, 0, ...]}
and I ended up writing the code like this:
for i in range(0, len(dati['signals'])):
#I extract the "quality" information using the alias
quality = extracted using(dati['alias'][i])
######
if quality == '0':
dati['nGOOD'][i] += 1
elif quality == '1':
dati['nBAD'][i] += 1
elif quality == '2':
dati['nFREEZE'][i] += 1
else:
raise Exception('Qualità sconosciuta')
This code worked, but I understand that using indexes is not the most pythonic why of doing stuff. I know I can use zip() to loop through different lists, but then I get tuples, which cannot be modified. Is there a better way to do this?
Thank you for your time.
@Wups: the final output of the code is the signal name and the quality counts, so I need to keep the informations linked.
@Pranav Hosangadi: if I understand correctly, using enumerate would be somewhat cleaner, but it is still not what I hoped for. I would still have to modify the quality by calling them by index. I had hoped for a way to access them during the loop.