[Tutor] List processing question - consolidating duplicate entries

Richard Querin rfquerin at gmail.com
Tue Nov 27 22:37:52 CET 2007


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]
[Bob,07099,projectD,3001,2]
[Bob,07129,projectA,4001,4]
[Bob,07099,projectD,4001,3]
[Bob,07129,projectA,4001,2]

Now I'd like to consolidate entries that are duplicates. Duplicates
meaning entries that share the same Name, job#, jobname and workcode.
So for the list above, there are 3 entries for projectA which have a
workcode of 4001. (there is a fourth entry for projectA but it's
workcode is 5001 and not 4001).

So I'd like to end up with a list so that the three duplicate entries
are consolidated into one with their hours added up:

[Bob,07129,projectA,4001,11]
[Bob,07129,projectA,5001,2]
[Bob,07101,projectB,4001,1]
[Bob,07140,projectC,3001,3]
[Bob,07099,projectD,3001,2]
[Bob,07099,projectD,4001,3]

I've tried doing it with brute force by stepping through each item and
checking all the other items for matches, and then trying to build a
new list as I go, but that's still confusing me - for instance how can
I delete the items that I've already consolidated so they don't get
processed again?.

I'm not a programmer by trade so I'm sorry if this is a basic computer
science question.

RQ


More information about the Tutor mailing list