Group

Overview

The gorup function will take a list of dictionaries, and then group the items in the list into a dictionary, with keys specified as an input.

Simple Example

In the following example, we create a list with 3 items. Each item has a name, two items have the same name, and a third item has a different name. We use the group function to create a dictionary, where the keys are the various names of the items, and the values is a list of all the items that share the name given by the key.

data = [{'name':'name1','age':20}, {'name':'name2','age':24}, {'name':'name1','age':50},] grouped_items = group(data, 'name') #this list should have 2 items list1 = grouped_items['name1'] #this list should have 1 item list2 = grouped_items['name2']

Try It