Count and Index

Is there a way I could count and index number of time item appear in a list?

something like if first.item then count := 1; else count := count + 1; end if;

itemcount
a1
a2
a3
b1
b2
c1
c2
c3