Given a list of anagrams, group anagrams by their sorted values (hint: the best solution uses a hash map).
Implement group_anagrams(words), where words is a list of lowercase strings. Return a list of groups, preserving the input order within each group and ordering groups by the first occurrence of their key. Two words belong to the same group when sorting their characters produces the same value.
The input may be empty, and duplicate words should remain duplicated in the output.
def group_anagrams(words):