Given a list of words, group the anagrams. Implement group_anagrams(words), preserving the order in which groups are first encountered and the original order of words within each group. The function accepts a list of lowercase strings and returns a list of word groups; for example, ['eat', 'tea', 'tan', 'ate'] returns [['eat', 'tea', 'ate'], ['tan']], while [] returns [].
def group_anagrams(words):