code: def dedent(string, indent_str='   ', max_levels=None):
      
      if len(indent_str) == 0:
          return string
  
      lines = string.splitlines()
  
      # Determine common (minumum) number of indentation levels, capped at
      # `max_levels` if given
      def num_indents(line):
          max_num = int(np.ceil(len(line) / len(indent_str)))
  
          for i in range(max_num):
              if line.startswith(indent_str):
                  line = line[len(indent_str):]
              else:
                  break
  
          return i
  
      num_levels = num_indents(min(lines, key=num_indents))
      if max_levels is not None:
          num_levels = min(num_levels, max_levels)
  
      # Dedent
      dedent_len = num_levels * len(indent_str)
      return '\n'.join(line[dedent_len:] for line in lines)
docs: Revert the effect of indentation.
  
      Examples
      --------
      Remove a simple one-level indentation:
  
      >>> text = '''<->This is line 1.
      ... <->Next line.
      ... <->And another one.'''
      >>> print(text)
      <->This is line 1.
      <->Next line.
      <->And another one.
      >>> print(dedent(text, '<->'))
      This is line 1.
      Next line.
      And another one.
  
      Multiple levels of indentation:
  
      >>> text = '''<->Level 1.
      ... <-><->Level 2.
      ... <-><-><->Level 3.'''
      >>> print(text)
      <->Level 1.
      <-><->Level 2.
      <-><-><->Level 3.
      >>> print(dedent(text, '<->'))
      Level 1.
      <->Level 2.
      <-><->Level 3.
  
      >>> text = '''<-><->Level 2.
      ... <-><-><->Level 3.'''
      >>> print(text)
      <-><->Level 2.
      <-><-><->Level 3.
      >>> print(dedent(text, '<->'))
      Level 2.
      <->Level 3.
      >>> print(dedent(text, '<->', max_levels=1))
      <->Level 2.
      <-><->Level 3.