def filter_by_value(dictionary, value):
return [value, [i for i in dictionary if dictionary[i] == value]]
And if you want to do it with all the values the dictionary has you can just do:
def group_by_values(dictionary):
#set ensures there are no repeated values
return [filter_by_value(dictionary, i) for i in set(dictionary.values())]
Last but not least, if you want the list to be sorted just add a sorting function after the set:
def group_by_values(dictionary):
#set ensures there are no repeated values
return [filter_by_value(dictionary, i) for i in sorted(set(dictionary.values()))]