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>With a dictionary, e.g. </p>

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

<p>You could try:</p>

<pre><code>print ''.join(['{0}{1}'.format(k, v) for k,v in dictionary.iteritems()])
</code></pre>

<p>Resulting in</p>

<blockquote>
  <p>a1c2b1</p>
</blockquote>

<p>If order matters, try using an <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" rel="nofollow">OrderedDict</a>, as described by <a href="http://stackoverflow.com/questions/9001509/how-can-i-sort-a-dictionary-by-key">this</a> post.</p>

python python-2.7 dictionary printing