Prolog getting frequency of list
问题 Working on a prolog assignment. I have a structure cnt(letter,number). I need to return a list of cnt where each cnt is the number of times each character appears (assuming that each item has already been sorted to place the same item one after each other). I have this so far: cnt(letter,number). freq([],[]). freq([A|L],Y) :- grab(A,Init,_), freq(L,[Init|Y]). grab works correctly takes a list of items and returns the list of the first duplicates as Init e.g grab([a,a,a,b,c], Init, Rest). will