Here is my dictionary:
D = {'G': ['R'],
'L': ['H'],
'H': ['H', 'L', 'T', 'M'],
'T': ['R'],
'S': ['M', 'L', 'H'],
'M': ['R']}
I am looking to create a list of the keys with the shortest list of values in this dictionary. In this case, I would get the output:
['G', 'L', 'T', 'M']
I have this code which successfully finds the first key with the shortest list of values, however, does not create a list.
min_key, min_value = min(d.items(), key = lambda x: len(set(x[1])))
This code simply returns 'G'
.
This was my attempt at creating a list:
li = [k for k, v in d.items() if v == min_key]
li
This returns an empty list.