def perm(s: str) -> {str, ...}:
    """Return set of all permutations of s.
    
    >>> perm("a") == {"a"}
    True
    >>> perm("ab") == {"ab", "ba"}
    True
    >>> perm("abc") == {"abc", "acb", "bac", "bca", "cab", "cba"}
    True
    """
    return (set(sum( # gather from
                [ # list of

                    # list of permutations produced by prefixing s[i]
                    # for each permutation of s with s[i] removed
                    [s[i] + p for p in perm(s[:i] + s[i+1:])]

                    # for each index in s
                    for i in range(len(s))],

                # pythonese to make sum gather (concatenate) lists
                [])) # (which it should have been designed to do, anyway!)

            # strings of length < 2 have just 1 permutation
            if len(s) > 1 else {s})

def perm2(s: str) -> {str, ...}:
    """Return set of all permutations of s.
    
    >>> perm2("a") == {"a"}
    True
    >>> perm2("ab") == {"ab", "ba"}
    True
    >>> perm2("abc") == {"abc", "acb", "bac", "bca", "cab", "cba"}
    True
    """
    return (set(sum( # gather from
                [ # list of...
                    
                    # list of permutations produced by inserting first
                    # character of s into each position of p
                    [p[:i] + s[0] + p[i:] for i in range(len(p) + 1)]

                    # for each permutation p of the rest of s
                    for p in perm2(s[1:])], 
                
                # pythonese to make sum gather (concatenate) lists
                [])) # (which it should have been designed to do, anyway!)

            # base case, when s has fewer than 2 characters
            if len(s) > 1 else {s})

if __name__ == '__main__':
    import doctest
    doctest.testmod()
    

