AnsweredAssumed Answered

Merge Python Dictionaries Based on Common Values

Question asked by mbabinski1988 on Oct 17, 2018
Latest reply on Oct 18, 2018 by Dan_Patterson

Greetings,

 

I have a list of Python dictionary objects. Each of the dictionaries has the same six keys. I'd like to be able to 'collapse' these dictionaries, combining them where five of the keys have identical values, and then separate the values for the sixth key with a comma.

 

For instance, if I was starting with:

 

myDictionaries = [{'Subdivision': u'NENW', 'Twp': u'026S', 'Range': u'033E', 'Sec': u'13', 'Sur Type': u'A', 'Meridian': u'33'}, 
{'Subdivision': u'NWNE', 'Twp': u'026S', 'Range': u'033E', 'Sec': u'13', 'Sur Type': u'A', 'Meridian': u'33'}]

 

Note that all of the key/value pairs in the two dictionaries are identical, except for Subdivision. So, what I would like to get is:

 

[{'Subdivision': u'NENW,NWNE', 'Twp': u'026S', 'Range': u'033E', 'Sec': u'13', 'Sur Type': u'A', 'Meridian': u'33'}]

 

Thanks for any help you can provide!

 

Micah

Outcomes