0

In python, i have this dictionary :

dict = {'key1':[a,b,c] , 'key2':[1,2,3], 'key3':[a,b,c]}

I need to group the keys with the same value (lists in this case) together in order to get a new dictionary:

res = {'group1':[key1,key3], 'group2':[key2]}

How can i do this in a easy/comprehensive way?

Ariel M
  • 175
  • 2
  • 10
  • The answer by Robert Rossney there applies here too. – Martijn Pieters Jan 07 '15 at 10:32
  • 1
    I'm having trouble understanding what you want (probably due to the use lists as values and the renaming of the values to `groupN`), Do you want an inverse mapping where each of your original values maps to a list of all the key pointing to that value? – Lanting Jan 07 '15 at 10:32
  • Since your values are *lists*, you cannot directly use them as dictionary keys; converting them to tuples would allow you to represent the group in immutable form suitable as dictionary keys however. – Martijn Pieters Jan 07 '15 at 10:34

0 Answers0