'Return the permutation needed to obtain ``i`` from the sorted
elements of ``i``. If custom sorting is desired, a key can be given.
Examples
>>> from sympy.combinatorics import Permutation
>>> Permutation.print_cyclic = True
>>> Permutation.from_sequence(\'SymPy\')
(4)(0 1 3)
>>> _(sorted("SymPy"))
[\'S\', \'y\', \'m\', \'P\', \'y\']
>>> Permutation.from_sequence(\'SymPy\', key=lambda x: x.lower())
(4)(0 2)(1 3)'

@classmethod
def from_sequence(self, i, key=None):

    ic = list(zip(i, list(range(len(i)))))
    if key:
        ic.sort(key=(lambda x: key(x[0])))
    else:
        ic.sort()
    return (~ Permutation([i[1] for i in ic]))
