-1

I have 567 arrays, each one with a specific length. I need to check each element of those 567 arrays, one by one, and depending on the element found, I need to increment a specific variable.

There are 100 counters created separetely, all started with 0, named counter_0, counter_1..., counter_99.

When I check each value of each array, I need to increment the counter corresponding to the array value, what means that if I found at position 1 of array 1 the value 90, I must increment counter_90. The length of the 567 arrays varies, but all the values cointained are from 0 to 99...

How could I do this whole operation in for loops, referring to the variables?

I've tried:

for i in range(567):
    #this is a way of refer to array_i:
    for j in range(len('array_{}'.format(i))):
         #check each position of this array
            #if position checked has value = 10, increment counter_10
            #if position checked has value = 22, increment counter_22
               ...

I don't know how to proceed.

martineau
  • 119,623
  • 25
  • 170
  • 301
L'recherche.
  • 77
  • 1
  • 11

1 Answers1

2

It might be better to have a list of 100 numbers,

counters = [0] * 100

and store the index in your dictionary:

update = { 10: 10, 22 : 22 }

Then you can say

counters[update[checked_value]]+=1
doctorlove
  • 18,872
  • 2
  • 46
  • 62