On 2016-08-30, Steve Graham <solitary.wanderer52@gmail.com> wrote:
The problem states:
Define a function that takes a list and returns a list indicating the number of times each (eql) element appears, sorted from most common
element to least common
$ txr
This is the TXR Lisp interactive listener of TXR 147.
Use the :quit command or type Ctrl-D on empty line to exit.
[group-by identity '(a a b a c b c c a a d e)]#H(() (e (e)) (d (d)) (a (a a a a a)) (c (c c c)) (b (b b)))
[hash-update [group-by identity '(a a b a c b c c a a d e)] length]#H(() (e 1) (d 1) (a 5) (c 3) (b 2))
(hash-pairs [hash-update [group-by identity '(a a b a c b c c a a de)] length])
((e 1) (d 1) (a 5) (c 3) (b 2))
[sort (hash-pairs [hash-update [group-by identity '(a a b a c b c ca a d e)] length]) > second]
((a 5) (c 3) (b 2) (d 1) (e 1))
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 362 |
Nodes: | 16 (2 / 14) |
Uptime: | 31:59:36 |
Calls: | 7,732 |
Files: | 12,873 |
Messages: | 5,731,053 |