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
> 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
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
> 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
[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
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
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
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
14 matches
Mail list logo