Record List to Record Set? in other words, grouping a list based on a variable

What is the best way to convert list to a set based on a chosen variable? In other words I want to group list based on a variable in the list. 


Employee List = Employee {emp_id, dept_id, name, designation}

I would like to get a Department Set or a new list having all dept_id (distinct of course) from the Employee List.

Hi Goldy Lukka,

What's the source of your data? You're probably better off performing that sort of operation directly on the database query.

@Jorge. I am seeking a solution outside database in general. In this specific case, the data is returned through a web service.