Hi I have a list of values. I want to get another list with the amount of times every values in that list occurs. This is fairly easy, but I also need to have the values which are not present in the original list, to be present in the frequency list, but then with value 0. For example:
I = [0,1,1,2,2,2,4,4,5,5,6,6,6,8,8,8]
What you expect:
freqI = [1,2,3,2,2,2,3,3]
What I need:
freqI = [1,2,3,0,2,2,3,0,3]
As you can see 3 and 7 are not present in I, though they are still accounted for in the frequency list.
My initial try ended up giving me the first kind of solution (with the intermediate values):
d = {x:I.count(x) for x in I}
sorted_x = sorted(d.iteritems(), key=operator.itemgetter(0))
How can I get the frequency count (aka histogram) of my array, with the intermediate values present ?
toList()and why are you calling it on something that's already a list?