Need an algorithm to group several parameters of a person under the persons name

Posted by QuickMist on Stack Overflow See other posts from Stack Overflow or by QuickMist
Published on 2010-05-09T05:50:42Z Indexed on 2010/05/09 5:58 UTC
Read the original article Hit count: 368

Hi. I have a bunch of names in alphabetical order with multiple instances of the same name all in alphabetical order so that the names are all grouped together. Beside each name, after a coma, I have a role that has been assigned to them, one name-role pair per line, something like whats shown below

name1,role1
name1,role2
name1,role3
name1,role8
name2,role8
name2,role2
name2,role4
name3,role1
name4,role5
name4,role1
...
..
.

I am looking for an algorithm to take the above .csv file as input create an output .csv file in the following format

name1,role1,role2,role3,role8
name2,role8,role2,role4
name3,role1
name4,role5,role1
...
..
.

So basically I want each name to appear only once and then the roles to be printed in csv format next to the names for all names and roles in the input file.

The algorithm should be language independent. I would appreciate it if it does NOT use OOP principles :-) I am a newbie.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about language-agnostic