How to create a python result array from a for loop? -


i want create results array results of loop example ran loop results 3,3,5,6,7,8,9,1,5 , want array go 10 id want create array looks [0, 0 1,1 2,0 3,2 4,0 5,2 6,1 7,1 8,1 9,1 10,0]

any appreciated beginner programmer

i suggest use dict instead of array. code follow:

sample=[3,3,5,6,7,8,9,1,5] def count_occurrence(sample):     occurrence={}     in range(10):         occurrence[i]=0     num in sample:         occurrence[num]+=1     return occurrence o=count_occurrence(sample) print(o) #if still want array mentioned: a=sorted(list(o.items())) print(a) 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -