toy list processing problem: collect similar terms
xahlee at gmail.com
Fri Oct 15 05:37:03 CEST 2010
On Sep 25, 9:05 pm, Xah Lee <xah... at gmail.com> wrote:
> here's a interesting toy list processing problem.
> I have a list of lists, where each sublist is labelled by
> a number. I need to collect together the contents of all sublists
> the same label. So if I have the list
> ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q
> r) (5 s t))
> where the first element of each sublist is the label, I need to
> ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t))
thanks all for many interesting solutions. I've been so busy in past
month on other computing issues and writing and never got around to
look at this thread. I think eventually i will, but for now just made
a link on my page to point to here.
now we have solutions in perl, python, ruby, common lisp, scheme lisp,
i'll write one soon. If someone would go thru all these solution and
make a good summary with consistent format/names of each solution...
that'd be very useful i think. (and will learn a lot, which is how i
find this interesting)
PS here's a good site that does very useful comparisons for those
learning multiple langs.
* 〈Lisp: Common Lisp, Scheme, Clojure, Emacs Lisp〉
* 〈Scripting Languages: PHP, Perl, Python, Ruby, Smalltalk〉
* 〈Platform Languages: C, C++, Objective C, Java, C#〉
* 〈ML: Standard ML, OCaml, F#, Scala, Haskell〉 http://hyperpolyglot.wikidot.com/ml
Xah ∑ http://xahlee.org/ ☄
More information about the Python-list