newbie/ merging lists of lists with items in common

2007-02-02 Thread ardief
Hi everyone Here is my problem: I have a list that looks like this - [['a', '13'], ['a', '3'], ['b', '6'], ['c', '12'], ['c', '15'], ['c', '4'], ['d', '2'], ['e', '11'], ['e', '5'], ['e', '16'], ['e', '7']] and I would like to end up with something like this, i.e. with the only one list per

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Miki
Hello, Here is my problem: I have a list that looks like this - [['a', '13'], ['a', '3'], ['b', '6'], ['c', '12'], ['c', '15'], ['c', '4'], ['d', '2'], ['e', '11'], ['e', '5'], ['e', '16'], ['e', '7']] and I would like to end up with something like this, i.e. with the only one list per

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Larry Bates
ardief wrote: Hi everyone Here is my problem: I have a list that looks like this - [['a', '13'], ['a', '3'], ['b', '6'], ['c', '12'], ['c', '15'], ['c', '4'], ['d', '2'], ['e', '11'], ['e', '5'], ['e', '16'], ['e', '7']] and I would like to end up with something like this, i.e. with the

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Paddy
On Feb 2, 1:55 pm, ardief [EMAIL PROTECTED] wrote: Hi everyone Here is my problem: I have a list that looks like this - [['a', '13'], ['a', '3'], ['b', '6'], ['c', '12'], ['c', '15'], ['c', '4'], ['d', '2'], ['e', '11'], ['e', '5'], ['e', '16'], ['e', '7']] and I would like to end up with

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Neil Cerutti
On 2007-02-02, ardief [EMAIL PROTECTED] wrote: Hi everyone Here is my problem: I have a list that looks like this - [['a', '13'], ['a', '3'], ['b', '6'], ['c', '12'], ['c', '15'], ['c', '4'], ['d', '2'], ['e', '11'], ['e', '5'], ['e', '16'], ['e', '7']] and I would like to end up with

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Laurent Pointal
ardief a écrit : Hi everyone Here is my problem: I have a list that looks like this - [['a', '13'], ['a', '3'], ['b', '6'], ['c', '12'], ['c', '15'], ['c', '4'], ['d', '2'], ['e', '11'], ['e', '5'], ['e', '16'], ['e', '7']] and I would like to end up with something like this, i.e. with the

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Paddy
On Feb 2, 2:39 pm, Paddy [EMAIL PROTECTED] wrote: On Feb 2, 1:55 pm, ardief [EMAIL PROTECTED] wrote: Hi everyone Here is my problem: I have a list that looks like this - [['a', '13'], ['a', '3'], ['b', '6'], ['c', '12'], ['c', '15'], ['c', '4'], ['d', '2'], ['e', '11'], ['e', '5'],

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Bart Ogryczak
On Feb 2, 2:55 pm, ardief [EMAIL PROTECTED] wrote: Hi everyone Here is my problem: I have a list that looks like this - [['a', '13'], ['a', '3'], ['b', '6'], ['c', '12'], ['c', '15'], ['c', '4'], ['d', '2'], ['e', '11'], ['e', '5'], ['e', '16'], ['e', '7']] and I would like to end up with

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Laurent Pointal
Neil Cerutti a écrit : On 2007-02-02, ardief [EMAIL PROTECTED] wrote: zip This is a job for... duhn-duhn-DH! Captain CHAOS! Er... I mean itertools.groupby. zip def key_func(t): return t[0] Not needed: -- from operator import itemgetter See in the example:

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Bart Ogryczak
On Feb 2, 3:19 pm, Larry Bates [EMAIL PROTECTED] wrote: l=[x for x in d.items()] d.items() is not an iterator, you don´t need this. This code is equivalent to l = d.items(). -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Neil Cerutti
On 2007-02-02, Laurent Pointal [EMAIL PROTECTED] wrote: Neil Cerutti a écrit : On 2007-02-02, ardief [EMAIL PROTECTED] wrote: zip This is a job for... duhn-duhn-DH! Captain CHAOS! Er... I mean itertools.groupby. zip def key_func(t): return t[0] Not needed: -- from

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread ardief
On Feb 2, 1:55 pm, ardief [EMAIL PROTECTED] wrote: Hi everyone Here is my problem: I have a list that looks like this - [['a', '13'], ['a', '3'], ['b', '6'], ['c', '12'], ['c', '15'], ['c', '4'], ['d', '2'], ['e', '11'], ['e', '5'], ['e', '16'], ['e', '7']] and I would like to end up with

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread James Stroud
ardief wrote: Hi everyone Here is my problem: I have a list that looks like this - [['a', '13'], ['a', '3'], ['b', '6'], ['c', '12'], ['c', '15'], ['c', '4'], ['d', '2'], ['e', '11'], ['e', '5'], ['e', '16'], ['e', '7']] and I would like to end up with something like this, i.e. with the

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread bearophileHUGS
Paddy: _ = [d[x0].append(x1) for x0,x1 in data] I think that you probably want: for text, num in data: d[text].append(num) ardief: thanks to everyone for the help, and the speed of it! It's really useful and I will spend some time working on understanding the code you posted. I'd be so

Re: newbie/ merging lists of lists with items in common

2007-02-02 Thread Paddy
On Feb 2, 10:34 pm, [EMAIL PROTECTED] wrote: Paddy: _ = [d[x0].append(x1) for x0,x1 in data] Yep, definitely a case of overdoing the list comprehensions when you throw away the list. I'll watch out for that in the future, Ta. - Paddy. I think that you probably want: for text, num in