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
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
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
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
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
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
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
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