Skip to content
Advertisement

itertools group by multiple keys

I am using itertools to group by a dictionary key using the below:

JavaScript

However I would like to group by ‘device_id’ and ‘port_id’ if possible, how can I add an additional key to the grouping?

Advertisement

Answer

Just use a tuple as key:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement