input: Write a python function to group anagrams from a list of words.
  assert group_anagrams(['eat', 'tea', 'tan', 'ate', 'nat', 'bat']) == [['eat', 'tea', 'ate'], ['tan', 'nat'], ['bat']]
  assert group_anagrams(['listen', 'silent', 'enlist', 'google', 'gogole']) == [['listen', 'silent', 'enlist'], ['google', 'gogole']]
  assert group_anagrams(['abcd', 'dcba', 'adbc', 'xyz']) == [['abcd', 'dcba', 'adbc'], ['xyz']]
output: def group_anagrams(words):
      from collections import defaultdict
      anagrams = defaultdict(list)
      
      for word in words:
          sorted_word = ''.join(sorted(word))
          anagrams[sorted_word].append(word)
      
      return list(anagrams.values())