code: def collapseuser(path):
      
      home = os.path.join(os.path.expanduser("~"), "")
      if path.startswith(home):
          path = os.path.join("~", path[len(home):])
      return path
docs: If path begins with the home directory, replaces the start of the path with "~/". Essentially the reverse of os.path.expanduser()