Python: how to get rid of spaces in str(dict)?
<p>For example, if you use str() on a dict, you get:</p>

<pre><code>&gt;&gt;&gt; str({'a': 1, 'b': 'as df'})
"{'a': 1, 'b': 'as df'}"
</code></pre>

<p>However, I want the string to be like:</p>

<pre><code>"{'a':1,'b':'as df'}"
</code></pre>

<p>How can I accomplish this?</p>

<p>There are two spaces naturally occurring. <code>': '</code> and <code>", "</code>. So I think you can just replace them using <code>replace</code> </p>

<pre><code>str({'a': 1, 'b': 'as df'}).replace(": ", ":").replace(", ", ",")
</code></pre>

<p>Note: To use this solution plz assume, you are not having <code>:</code> or <code>,</code> in any of the values or keys of the dictionary. </p>

python