How to remove the all the curly bracket in dictionary of dictionaries
<p>I wish to remove all the curly brackets from my current output. My current output as shown below:</p>

<pre><code> {'Chin PTE LTD': {'Carrot Cake': 22, 'Chocolate Cake': 12, 'Beer': 89}, 'COQ 
SEAFOOD': {'GRILLED AUSTRALIA ANGU': 1, 'CRISPY CHICKEN WINGS': 1
}}
</code></pre>

<p>My current code as shown below:</p>

<pre><code>for merchant, product, quantity in big_list:
    d[merchant][product] += quantity

print ({ k:dict(v) for k,v in d.items() })
</code></pre>

<p>My desired output:</p>

<pre><code>'Chin PTE LTD': 'Carrot Cake': 22, 'Chocolate Cake': 12, 'Beer': 89, 'COQ 
    SEAFOOD': 'GRILLED AUSTRALIA ANGU': 1, 'CRISPY CHICKEN WINGS': 1
</code></pre>

<p>As I am still new to python, may I ask if i wish to remove the all the curly brackets in the dictionary of dictionaries. Would my desired output be achievable? If so, how should I go about doing it? Any suggestions / ideas would be appreciated. Thank you.</p>

<p>Build up the string like so</p>

<pre><code>d = {'Chin PTE LTD': {'Carrot Cake': 22, 'Chocolate Cake': 12, 'Beer': 89}, 'COQ SEAFOOD': {'GRILLED AUSTRALIA ANGU': 1, 'CRISPY CHICKEN WINGS': 1}}

st = ', '.join('%r: %s' % (k, ', '.join('%r: %r' % (sk, sv) for sk, sv in v.items())) for k, v in d.items())
print(st)
</code></pre>

<p>This code builds the string by first iterating over the outer dict. It appends the key to the string (plus a ':' in keeping with your formatting requirements). Then it iterates over the inner dict and appends the key and value the same way. It uses the <code>%r</code> format specifier which means that the elements being printed are converted using their <code>repr</code> function. This gives the strings their quotes, without having to manually add them.</p>

<p>You can't count on the order being fixed though. So for different runs you'll get slightly different orders. </p>

<p>Output looks like</p>

<blockquote>
  <p>'Chin PTE LTD': 'Carrot Cake': 22, 'Chocolate Cake': 12, 'Beer': 89, 'COQ SEAFOOD': 'GRILLED AUSTRALIA ANGU': 1, 'CRISPY CHICKEN WINGS': 1 </p>
</blockquote>

<p>Someone could probably wrap it up into a giant <code>join</code>/comprehension to make it more functional if they really wanted to.</p>

python dictionary