Python How to print dictionary in one line?
<p>Hi I am new to Python and I am struggling regarding how to print dictionary.</p>

<p>I have a dictionary as shown below.</p>

<pre><code>dictionary = {a:1,b:1,c:2}
</code></pre>

<p>How can I print dictionary in one line as shown below?</p>

<pre><code>a1b1c2
</code></pre>

<p>I want to print keys and values in one line but could not figure out by myself.</p>

<p>I would appreciate your advice!</p>

<p>If you want a string to contain the answer, you could do this:</p>

<pre><code>&gt;&gt;&gt; dictionary = {'a':1,'b':1,'c':2}
&gt;&gt;&gt; result = "".join(str(key) + str(value) for key, value in dictionary.items())
&gt;&gt;&gt; print(result)
c2b1a1
</code></pre>

<p>This uses the join method on an empty string. Dict's are not ordered, so the order of the output may vary.</p>

python python-2.7 dictionary printing