I am trying to find an efficient solution for following problem:
I have a list of dictionaries with each dictionary having the same set of keys as another one. The associating values can be equal inter-dictionaries. I am trying to find the minimum number of keys and their associating values which would make each dictionary unique.
For example for a list consisting of three dictionaries:
list = [a, b, c]
where
a = {"key1": "alpha", "key2": "beta", "key3": "gamma"}
b = {"key1": "alpha", "key2": "beta", "key3": "eta"}
c = {"key1": "alpha", "key2": "zeta", "key3": "eta"}
All three dictionaries have the same value for key1 therefore this key can be eliminated since its inclusion does not determine the uniqueness of a dictionary. On the other hand, key2 and key3 must be both included since their collective make the respective dictionary unique.
a = {"key2": "beta", "key3": "gamma"}
b = {"key2": "beta", "key3": "eta"}
c = {"key2": "zeta", "key3": "eta"}
I assume that I loop through the list of dictionaries so using for example collections.Counter within an iteration is possible. The number of dictionaries within the list is a variable along with the number of keys. I would like to iterate through the list the least number possible (for example once while updating one or multiple Counters?). I am fairly sure that there is an appropriate algorithm for this problem but could not find it with my search keywords.
Edit: Each final dict must have the same keys as the others. Therefore keeping a different set of keys for each individual dict is not an option.