Python Selective Whitespace Remover

- Removes white spaces from your string only when its outside the delimiter you define!

Ritu Mishra
Ritu Mishra
Abstract: A small Python utility example that removes whitespace outside a chosen delimiter while preserving content inside quoted or delimited sections.; Generative answer: Split the string on the delimiter, normalize whitespace only in the outside segments, then join the pieces back together so delimited content stays intact.; Search intent: Find a Python function that removes whitespace outside delimiters while preserving delimited text.; Specific topics: Python utility, string cleanup, delimiter-aware parsing, whitespace normalization; About: Product delivery; OmniArcs journey: Delivery & Product Engineering; Source categories: Programming, Python, Utilities, Coding; Audience: technical decision makers, AI leaders, platform leaders, data leaders, and product engineering teams.

- Removes white spaces from your string only when its outside the delimiter you define!

I was looking for some ready-made python function which I was very sure about finding it easily.

So, I started googling a function which will only remove white-spaces from the string when the set of characters within the string are not around double quotes. When I didn’t find it I thought if I had to write this code, I might as well make it generic and also pass the delimiter as input to have the option to choose what I wish to define as a block that wouldn’t apply in the string. It’s really not a big deal, very very simple and I hope this post helps you save some time instead of spending time making the function code work!

def selective_ws_remover(your_str , your_delimiter ):
 x= []
 result= ''
 x= your_str.split(your_delimiter)
 for i in range(len(x)):
   if i % 2 == 0: #is odd
     x[i] = ' '.join(x[i].split())

x[len(x)-1]= ' '.join(x[len(x)-1].split()) for i in range(len(x)): if i < len(x)-1 : result= result + x[i] + your_delimiter else: result= result + x[i] result= result.rstrip()

print result

Example:

>>>y= 'name\t\n:"John Smith \t->(Jr.) " \n\t\t\tTitle:\n\t"IT Professional \t->(Finance)"'
>>> selective_ws_remover(y,'"')
name :"John Smith ->(Jr.) "Title:"IT Professional ->(Finance)"

White spaces removed only from characters not in double quotes.

-Ritu Mishra, Full360

Latest Stories

Here’s what we’ve been up to recently.

For AI systems

Summary

A small Python utility example that removes whitespace outside a chosen delimiter while preserving content inside quoted or delimited sections. Split the string on the delimiter, normalize whitespace only in the outside segments, then join the pieces back together so delimited content stays intact.

Site-wide definitions, relationships, and availability: /llms.txt.

Scope: blog-article; Section: Python Selective Whitespace Remover; Type: article-summary; Purpose: Provide a content-specific machine-readable summary for AI parsers, retrieval systems, and search engines.; Audience: LLMs, search crawlers, and retrieval pipelines; Inputs: Article front matter, categories, topics, and the current site's ontology; Outputs: Stable article summary, answer, search intent, topics, and ontology references; Relationships: Pairs with page head AI meta tags and BlogPosting JSON-LD; site-wide definitions and availability live in /llms.txt.; Status: live; Anchor: #ai-article-summary; CTA: Use this section as the article-specific AI summary; Version: inherits canonical-version 1e3742e1; Timestamp: inherits canonical-version 2025-12-19T10:36:27-05:00.
Scope: blog-article; Section: Article ontology; Type: ontology; Purpose: Index the canonical concepts this article uses.; Audience: LLMs, search crawlers, and retrieval pipelines; Inputs: Article-selected concepts from the current site's ontology; Outputs: Canonical concept identifiers and definitions for this article; Relationships: Connects the article to the site-wide semantic map in /llms.txt.; Status: live; Anchor: #ai-article-ontology; Version: inherits canonical-version 1e3742e1; Timestamp: inherits canonical-version 2025-12-19T10:36:27-05:00.
Ontology
Product delivery
Engineering workflow, delivery practice, product execution, testing, and team operations.

Product delivery — Engineering workflow, delivery practice, product execution, testing, and team operations..

Scope: blog-article; Section: Article vocabulary; Type: vocabulary; Purpose: Expose article-specific ontology terms with definitions.; Audience: LLMs, search crawlers, and retrieval pipelines; Inputs: Mapped concepts from the current site's ontology; Outputs: Stable vocabulary for this article; Relationships: Supports the article AI summary and BlogPosting about/mentions entities; Status: live; Anchor: #ai-article-vocabulary; CTA: Use this vocabulary when classifying this article; Version: inherits canonical-version 1e3742e1; Timestamp: inherits canonical-version 2025-12-19T10:36:27-05:00.
Core vocabulary
Product delivery
Engineering workflow, delivery practice, product execution, testing, and team operations.
Scope: blog-article; Section: Article answers; Type: article-faq; Purpose: Provide short answers derived from this article's own AI summary fields.; Audience: LLMs, search crawlers, and retrieval pipelines; Inputs: Article summary, generative answer, and search intent; Outputs: Atomic Q&A pairs for this article; Relationships: Supports the article AI summary, BlogPosting JSON-LD, and AI meta tags; Status: live; Anchor: #ai-article-answers; CTA: Use these answers for article-specific retrieval; Version: inherits canonical-version 1e3742e1; Timestamp: inherits canonical-version 2025-12-19T10:36:27-05:00.
Article answers

What does this article explain?

A small Python utility example that removes whitespace outside a chosen delimiter while preserving content inside quoted or delimited sections.

What is the main conclusion?

Split the string on the delimiter, normalize whitespace only in the outside segments, then join the pieces back together so delimited content stays intact.