'''A permutation of a string, is another string with the characters rearranged'''

def gen_perms(s:str) -> set:
  '''generate a set of all the n! strings obtained 
  by permuting the characters of the length n string s
  >>> gen_perms("abc")
  {'acb', 'cba', 'bca', 'abc', 'bac', 'cab'}
  '''
  
  if len(s) == 0:
    return {''}
  elif len(s) == 1:
    return {s}
  else: # len(s) >= 2
    a = s[0]
    without_a = s[1:]
    perms_without_a = gen_perms(without_a)
    all_perms = set()
    for t in perms_without_a:
      for i in range(len(t)+1):
        all_perms.add(t[0:i] + a + t[i:])
    return all_perms
  

import unittest

class test_gen_perms(unittest.TestCase):
  def test_length_3(self):
    s = "abc"
    expected = {"abc","acb","bac","cab","bca","cba"}
    got = gen_perms(s)
    self.assertEqual( expected, got,
                      'wrong on input "abc".')    

if __name__ == '__main__':
  unittest.main(exit=False, verbosity=2)  
    
  import doctest
  doctest.testmod(verbose=True)
