Re: toy list processing problem: collect similar terms

2013-02-06 Thread Nick Mellor
Oops! Not that sort stability is used in this algorithm. Was thinking of something else :-) N On Thursday, 7 February 2013 10:25:36 UTC+11, Nick Mellor wrote: > Python 3 version: > > > > from collections import defaultdict > > > > data = > ((0,'a','b'),(1,'c','d'),(2,'e','f'),(3,'g','h')

Re: toy list processing problem: collect similar terms

2013-02-06 Thread Nick Mellor
Python 3 version: from collections import defaultdict data = ((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')) register = defaultdict(list) for number, *letters in data: register[number].extend(letters) final = [] for i

Re: toy list processing problem: collect similar terms

2013-02-06 Thread Nick Mellor
You can just flatten the list using itertools and collate the results using defaultdict: import itertools from collections import defaultdict sequence = ((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')) # flatten the list

Re: toy list processing problem: collect similar terms

2011-02-16 Thread WJ
Xah Lee 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 > sharing > 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

Re: toy list processing problem: collect similar terms

2011-02-10 Thread WJ
Pascal J. Bourguignon wrote: > Xah Lee writes: > > > > 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 > > sharing > > the same label. So if I have the list

Re: toy list processing problem: collect similar terms

2010-10-14 Thread Xah Lee
On Sep 25, 9:05 pm, Xah Lee 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 > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (

Re: toy list processing problem: collect similar terms

2010-10-07 Thread sln
On Wed, 06 Oct 2010 10:52:19 -0700, s...@netherlands.com wrote: >On Sat, 25 Sep 2010 21:05:13 -0700 (PDT), Xah Lee 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

Re: toy list processing problem: collect similar terms

2010-10-06 Thread sln
On Sat, 25 Sep 2010 21:05:13 -0700 (PDT), Xah Lee 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 >sharing >the same label. So if I have the list > >((0 a b) (

Re: toy list processing problem: collect similar terms

2010-09-30 Thread namekuseijin
On 30 set, 09:35, namekuseijin wrote: > On 29 set, 11:04, w_a_x_man wrote: > > > > > On Sep 26, 9:24 am, p...@informatimago.com (Pascal J. Bourguignon) > > wrote: > > > > Xah Lee writes: > > > > here's a interesting toy list processing problem. > > > > > I have a list of lists, where each sublis

Re: toy list processing problem: collect similar terms

2010-09-30 Thread namekuseijin
On 29 set, 11:04, w_a_x_man wrote: > On Sep 26, 9:24 am, p...@informatimago.com (Pascal J. Bourguignon) > wrote: > > > > > Xah Lee writes: > > > 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 to

Re: toy list processing problem: collect similar terms

2010-09-29 Thread w_a_x_man
On Sep 26, 9:24 am, p...@informatimago.com (Pascal J. Bourguignon) wrote: > Xah Lee writes: > > 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 > > sharing > > th

Re: toy list processing problem: collect similar terms

2010-09-28 Thread John Bokma
Paul Rubin writes: > John Bokma writes: >> Xah Lee writes: ... >> Can you stop crossposting? > > John, can you ALSO stop crossposting? Since the issue is on-topic in all groups: no. I did set a follow-up header, which you ignored and on top of that redirected the thing to comp.lang.python. S

Re: toy list processing problem: collect similar terms

2010-09-28 Thread Paul Rubin
John Bokma writes: > Xah Lee writes: ... > Can you stop crossposting? John, can you ALSO stop crossposting? -- http://mail.python.org/mailman/listinfo/python-list

Re: toy list processing problem: collect similar terms

2010-09-28 Thread John Bokma
Xah Lee writes: > can you stop this? Can you stop crossposting? And if there is really, really a need to crosspost, can you please set the follow-up to? > doesn't seems fruitful to keep on this. > > if you don't like my posts, ignore them? i don't post in > comp.lang.python or comp.lang.perl.mi

Re: toy list processing problem: collect similar terms

2010-09-28 Thread Xah Lee
On Sep 27, 9:34 pm, John Bokma wrote: > Seebs writes: > > fup set to poster > > > On 2010-09-28, John Bokma wrote: > >> Seebs writes: > >>> On 2010-09-26, J?rgen Exner wrote: > It was livibetter who without any motivation or reasoning posted Python > code in CLPM. > > >>> Not exactly

Re: toy list processing problem: collect similar terms

2010-09-27 Thread John Bokma
Seebs writes: fup set to poster > On 2010-09-28, John Bokma wrote: >> Seebs writes: >>> On 2010-09-26, J?rgen Exner wrote: It was livibetter who without any motivation or reasoning posted Python code in CLPM. > >>> Not exactly; he posted it in a crossposted thread, which happened to

Re: toy list processing problem: collect similar terms

2010-09-27 Thread Seebs
On 2010-09-28, John Bokma wrote: > Seebs writes: >> On 2010-09-26, J?rgen Exner wrote: >>> It was livibetter who without any motivation or reasoning posted Python >>> code in CLPM. >> Not exactly; he posted it in a crossposted thread, which happened to include >> CLPM and other groups, includin

Re: toy list processing problem: collect similar terms

2010-09-27 Thread John Bokma
Seebs writes: > On 2010-09-26, J?rgen Exner wrote: >> It was livibetter who without any motivation or reasoning posted Python >> code in CLPM. > > Not exactly; he posted it in a crossposted thread, which happened to include > CLPM and other groups, including comp.lang.python. > > It is quite pos

How to Deal with Xah Lee Spam/Abuse (was: toy list processing problem: collect similar terms)

2010-09-27 Thread John Bokma
Seebs writes: > On 2010-09-26, Xah Lee wrote: >> On Sep 25, 11:17??pm, Paul Rubin wrote: >>> Python solution follows (earlier one with an error cancelled). ??All >>> crossposting removed since crossposting is a standard trolling tactic. > >> btw, i disagree about your remark on crossposting. >

Re: toy list processing problem: collect similar terms

2010-09-27 Thread Seebs
On 2010-09-26, J?rgen Exner wrote: > It was livibetter who without any motivation or reasoning posted Python > code in CLPM. Not exactly; he posted it in a crossposted thread, which happened to include CLPM and other groups, including comp.lang.python. It is quite possible that he didn't know ab

Re: toy list processing problem: collect similar terms

2010-09-27 Thread Seebs
On 2010-09-26, Xah Lee wrote: > On Sep 25, 11:17??pm, Paul Rubin wrote: >> Python solution follows (earlier one with an error cancelled). ??All >> crossposting removed since crossposting is a standard trolling tactic. > btw, i disagree about your remark on crossposting. You're wrong. Crosspost

Re: reduced-tagged (was Re: toy list processing problem: collect similar terms)

2010-09-27 Thread Steven D'Aprano
On Mon, 27 Sep 2010 08:18:22 -0700, Mirko wrote: > Here is my Common Lisp (and I only care about Common Lisp answers) Good for you. So why are you spamming other newsgroups with your CL solution? Not once, but three times. Replies to /dev/null. -- Steven -- http://mail.python.org/mailman/lis

Re: toy list processing problem: collect similar terms

2010-09-27 Thread ccc31807
On Sep 26, 12:05 am, Xah Lee 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 > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (

Re: reduce-tagged (was Re: toy list processing problem: collect similar terms)

2010-09-27 Thread Mirko
On Sep 27, 11:40 am, Mirko wrote: > On Sep 27, 11:18 am, Mirko wrote: > > > > > On Sep 26, 12:05 am, Xah Lee wrote: > > > I am hijacking the following post and driving it to Cuba (the Monthy > > Python fans will know what I refer to).  I want to create a `reduce'- > > like function that can hand

Re: reduce-tagged (was Re: toy list processing problem: collect similar terms)

2010-09-27 Thread Mirko
On Sep 27, 11:18 am, Mirko wrote: > On Sep 26, 12:05 am, Xah Lee wrote: > > I am hijacking the following post and driving it to Cuba (the Monthy > Python fans will know what I refer to).  I want to create a `reduce'- > like function that can handle similar problems. > > Xah said: > > > > > here's

reduced-tagged (was Re: toy list processing problem: collect similar terms)

2010-09-27 Thread Mirko
On Sep 26, 12:05 am, Xah Lee wrote: I am hijacking the following post and driving it to Cuba (the Monthy Python fans will know what I refer to). I want to create a `reduce'- like function that can handle similar problems. Xah said: > here's a interesting toy list processing problem. > > I have

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Ertugrul Söylemez
Ertugrul Söylemez wrote: > In Haskell the solution looks like this: > > [...] And before anyone starts to rant, I didn't pay attention to where I'm X-posting this stuff. Sorry for that. But on the other hand you could say that I'm giving the Perl people (apparently the only people feeling the

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Ertugrul Söylemez
Xah Lee 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 sharing 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)

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Rhodri James
On Sun, 26 Sep 2010 23:16:24 +0100, Jürgen Exner wrote: I have solved my problems with Xah years ago, that's what killfiles are for. And I have no idea why you are bringing up Xah in your current rant. It was livibetter who without any motivation or reasoning posted Python code in CLPM. If a

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Bakul Shah
On 9/25/10 9:05 PM, Xah Lee 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 sharing the same label. So if I have the list ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j)

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Xah Lee
On Sep 26, 7:56 am, Sherm Pendley wrote: > Jürgen Exner writes: > > Alexander Burger wrote: > >>In PicoLisp: > > > What the f does PicoLisp have to with Perl? > > It's Xah. He cross-posts in an attempt to start a language feud. > > Please don't feed the troll. sorry i disagree. And please d

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Xah Lee
2010-09-26 On Sep 25, 11:17 pm, Paul Rubin wrote: > Python solution follows (earlier one with an error cancelled).  All > crossposting removed since crossposting is a standard trolling tactic. > >     from collections import defaultdict > >     def collect(xss): >         d = defaultdict(list) >

Re: toy list processing problem: collect similar terms

2010-09-26 Thread John Bokma
Jürgen Exner writes: > livibetter wrote: >>Here is mine for Python: > > What the f*** does Python have to do with Perl? Clueless fuck. I unsubscribed from comp.lang.perl.misc to avoid the retards like you and now you come in via the backdoor. If you have a problem with Xah report him with Googl

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Ben Morrow
Quoth p...@informatimago.com (Pascal J. Bourguignon): > > It's too complex. Just write: > > (let ((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 Unless you're going to talk about Perl, please take clpmisc out of the xpost. Ben -- h

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Sherm Pendley
Jürgen Exner writes: > livibetter wrote: >>Here is mine for Python: > > What the f*** does Python have to do with Perl? Xah is a cross-posting troll. Please don't feed the troll. sherm-- -- Sherm Pendley Cocoa Developer -

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Sherm Pendley
Jürgen Exner writes: > Alexander Burger wrote: >>In PicoLisp: > > What the f does PicoLisp have to with Perl? It's Xah. He cross-posts in an attempt to start a language feud. Please don't feed the troll. sherm-- -- Sherm Pendley

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Pascal J. Bourguignon
Xah Lee writes: > 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 > sharing > 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

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Dr.Ruud
On 2010-09-26 06:05, Xah Lee wrote: I have a list of lists, where each sublist is labelled by a number. I need to collect together the contents of all sublists sharing 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

Re: toy list processing problem: collect similar terms

2010-09-26 Thread Arnaud Delobelle
On 26 Sep, 08:47, livibetter wrote: > Here is mine for Python: > > l = [[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']] > d = {} > for idx, items in [(e[0], e[1:]) for e in l]: d[idx] = d[idx]

Re: toy list processing problem: collect similar terms

2010-09-26 Thread livibetter
Here is mine for Python: l = [[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']] d = {} for idx, items in [(e[0], e[1:]) for e in l]: d[idx] = d[idx] + items if idx in d else items print d.values()

Re: toy list processing problem: collect similar terms

2010-09-25 Thread Paul Rubin
Python solution follows (earlier one with an error cancelled). All crossposting removed since crossposting is a standard trolling tactic. from collections import defaultdict def collect(xss): d = defaultdict(list) for xs in xss: d[xs[0]].extend(xs[1:])

Re: toy list processing problem: collect similar terms

2010-09-25 Thread Alexander Burger
In PicoLisp: (mapcar '((X) (apply conc (cdr X))) (group List) ) Cheers, - Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: toy list processing problem: collect similar terms

2010-09-25 Thread Gary Herron
On 09/25/2010 09:05 PM, Xah Lee 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 sharing the same label. So if I have the list ((0 a b) (1 c d) (2 e f) (3 g h) (1

toy list processing problem: collect similar terms

2010-09-25 Thread Xah Lee
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 sharing 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