code: def deduplicate(s, ch):
      
      return ch.join([substring for substring in s.strip().split(ch) if substring])
docs: From http://stackoverflow.com/q/42216559/610569
  
          s = 'this is   an   irritating string with  random spacing  .'
          deduplicate(s)
          'this is an irritating string with random spacing .'