Re: [Tutor] List processing question - consolidating duplicate entries

2007-11-29 Thread Kent Johnson
Richard Querin wrote: > import itertools, operator > for k, g in itertools.groupby(sorted(data), key=operator.itemgetter(0, > 1, 2, 3)): > print k, sum(item[4] for item in g) > > > > I'm trying to understand what's going on in the for statement but I'm > having troubles. The i

Re: [Tutor] List processing question - consolidating duplicate entries

2007-11-29 Thread Richard Querin
On Nov 27, 2007 5:40 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > > This is a two-liner using itertools.groupby() and operator.itemgetter: > > data = [['Bob', '07129', 'projectA', '4001',5], > ['Bob', '07129', 'projectA', '5001',2], > ['Bob', '07101', 'projectB', '4001',1], > ['Bob', '07140', 'pr

Re: [Tutor] List processing question - consolidating duplicate entries

2007-11-28 Thread Kent Johnson
Michael Langford wrote: > What you want is a set of entries. Not really; he wants to aggregate entries. > # remove duplicate entries > # > # myEntries is a list of lists, > #such as [[1,2,3],[1,2,"foo"],[1,2,3]] > # > s=set() > [s.add(tuple(x)) for x in myEntries] A set can be constructed d

Re: [Tutor] List processing question - consolidating duplicateentries

2007-11-28 Thread Tiger12506
> s=set() > [s.add(tuple(x)) for x in myEntries] > myEntries = [list(x) for x in list(s)] This could be written more concisely as... s = set(tuple(x) for x in myEntries) myEntries = [list(x) for x in list(s)] Generator expressions are really cool. Not what the OP asked for exactly. He wanted to

Re: [Tutor] List processing question - consolidating duplicate entries

2007-11-27 Thread Michael Langford
What you want is a set of entries. Unfortunately, python lists are not "hashable" which means you have to convert them to something hashable before you can use the python set datatype. What you'd like to do is add each to a set while converting them to a tuple, then convert them back out of the se

Re: [Tutor] List processing question - consolidating duplicate entries

2007-11-27 Thread Kent Johnson
bob gailer wrote: > 2 - Sort the list. Create a new list with an entry for the first name, > project, workcode. Step thru the list. Each time the name, project, > workcode is the same, accumulate hours. When any of those change, create > a list entry for the next name, project, workcode and agai

Re: [Tutor] List processing question - consolidating duplicate entries

2007-11-27 Thread bob gailer
Richard Querin wrote: > I'm trying to process a list and I'm stuck. Hopefully someone can help > me out here: > > I've got a list that is formatted as follows: > [Name,job#,jobname,workcode,hours] > > An example might be: > > [Bob,07129,projectA,4001,5] > [Bob,07129,projectA,5001,2] > [Bob,07101,pr

Re: [Tutor] List processing question - consolidating duplicate entries

2007-11-27 Thread John Fouhy
On 28/11/2007, Richard Querin <[EMAIL PROTECTED]> wrote: > I've got a list that is formatted as follows: > [Name,job#,jobname,workcode,hours] [...] > Now I'd like to consolidate entries that are duplicates. Duplicates > meaning entries that share the same Name, job#, jobname and workcode. > So for

[Tutor] List processing question - consolidating duplicate entries

2007-11-27 Thread Richard Querin
I'm trying to process a list and I'm stuck. Hopefully someone can help me out here: I've got a list that is formatted as follows: [Name,job#,jobname,workcode,hours] An example might be: [Bob,07129,projectA,4001,5] [Bob,07129,projectA,5001,2] [Bob,07101,projectB,4001,1] [Bob,07140,projectC,3001,3

Re: [Tutor] List processing

2005-06-01 Thread Alan G
> I have a load of files I need to process. Each line of a file looks > something like this: > > eYAL001C1 Spar 81 3419 4518 4519 2 1 > > So basically its a table, separated with tabs. What I need to do is make a > new file where all the entries in the table are those where the values in > columns

Re: [Tutor] List processing

2005-06-01 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Hi, > > I have a load of files I need to process. Each line of a file looks > something like this: > > eYAL001C1 Spar81 3419451845192 1 > > So basically its a table, separated with tabs. What I need to do is make a > new file whe

Re: [Tutor] List processing

2005-06-01 Thread Terry Carroll
On 1 Jun 2005 [EMAIL PROTECTED] wrote: > eYAL001C1 Spar81 3419451845192 1 > > So basically its a table, separated with tabs. What I need to do is make > a new file where all the entries in the table are those where the values > in columns 1 and 5 were present

Re: [Tutor] List processing

2005-06-01 Thread Danny Yoo
On 1 Jun 2005 [EMAIL PROTECTED] wrote: > I have a load of files I need to process. [text cut] > So basically its a table, separated with tabs. What I need to do is make > a new file where all the entries in the table are those where the values > in columns 1 and 5 were present as a pair more t

[Tutor] List processing

2005-06-01 Thread cgw501
Hi, I have a load of files I need to process. Each line of a file looks something like this: eYAL001C1 Spar81 3419451845192 1 So basically its a table, separated with tabs. What I need to do is make a new file where all the entries in the table are those