There is a two-dimensional list in which the number of large lists equals the input (n = 3) from the user:

l1=[] n=int(input()) for i in range(n) : l1.append([]) for s in range(1): l1[i].append(0) print(l1) 

in general: here l1=[[0], [0], [0]] it should be compared with another list (it is already static). For example: [1, 3, 3, 1] but I need not to compare with the list values ​​themselves, but compare with the index. For example, if the first number 1 is equal to the index in the list ( l1 ) at number 1, then you need to add +1 to the value this index.

Input

 3 1331 

Weekends

 2 0 2 
  • 2
    nothing is not clear, add an example of input and output data - Pavel Durmanov
  • rules, I hope understandable - Double Mid

1 answer 1

Do I understand what you need?

 number = [0, 0, 0] l1 = [1, 3, 3, 1] for i in l1: number[i-1] += 1 print(number) # [2, 0, 2] 

 number = [[0], [0], [0]] l1 = [1, 3, 3, 1] for i in l1: number[i-1][0] += 1 print(number) # [[2], [0], [2]] number = [i[0] for i in number] print(number) # [2, 0, 2] 
  • And how to make it work as well but with such a view? [[0], [0], [0]] - Double Mid
  • @DoubleMid, updated the answer - gil9red