我有一个这样的列表:
'(("Alpha" . 1538)
("Beta" . 8036)
("Gamma" . 8990)
("Beta" . 10052)
("Alpha" . 12837)
("Beta" . 13634)
("Beta" . 14977)
("Beta" . 15719)
("Alpha" . 17075)
("Rho" . 18949)
("Gamma" . 21118)
("Gamma" . 26923)
("Alpha" . 31609))
Run Code Online (Sandbox Code Playgroud)
如何计算列表中每个元素的汽车中术语的总出现次数?基本上我想要:
(("Alpha" . 4)
("Beta" . 5)
("Gamma" . 3)
("Rho" . 1))
Run Code Online (Sandbox Code Playgroud)
不,这不是功课.我还没有"在Lisp中思考"的事情.
在C#中,我会使用LINQ来执行此操作.我也可以在lisp中使用while循环等,但我想这样做的方式似乎过于复杂.
编辑
这就是我所拥有的:
(defun count-uniq (list)
"Returns an alist, each item is a cons cell where the car is
a unique element of LIST, and the …Run Code Online (Sandbox Code Playgroud)