input: Write a python function to generate all permutations of a given list of elements.
  assert permutations([1, 2]) == [[1, 1], [2, 2], [1, 2], [2, 1]]
  assert permutations(['a', 'b']) == [['a', 'a'], ['b', 'b'], ['a', 'b'], ['b', 'a']]
  assert permutations([1, 2, 3]) == [[1, 1, 1], [2, 2, 2], [3, 3, 3], [1, 2, 1], [2, 1, 2], [3, 1, 3], [1, 3, 1], [2, 3, 2], [3, 2, 3], [1, 1, 2], [2, 2, 1], [3, 3, 1], [1, 2, 3], [2, 1, 3], [3, 1, 2], [1, 3, 2], [2, 3, 1], [3, 2, 1], [1, 1, 3], [2, 2, 3], [3, 3, 2], [1, 2, 2], [2, 1, 1], [3, 1, 1], [1, 3, 3], [2, 3, 3], [3, 2, 2], [1, 1, 3], [2, 2, 3], [3, 3, 2], [1, 2, 3], [2, 1, 3], [3, 1, 2], [1, 3, 2], [2, 3, 1], [3, 2, 1]]
output: def permutations(elements):
      if len(elements) == 0:
          return [[]]
      result = []
      for i in range(len(elements)):
          for p in permutations(elements[:i] + elements[i+1:]):
              result.append([elements[i]] + p)
      return result