How to parse Python set-inside-list structure into text?
<p>I have the following strange format I am trying to parse. </p>

<p>The data structure I am trying to parse is a "set" of key-value pairs in a list:</p>

<pre><code>[{'key1:value1', 'key2:value2', 'key3:value3',...}] 
</code></pre>

<p>That's the only data I have, and it needs to be processed. I don't think this can be described as a Python data structure, but I need to parse this to become a string like </p>

<pre><code>'key1:value1, key2:value2, key3:value3'. 
</code></pre>

<p>Is this doable?</p>

<p>EDIT: Yes, it is <code>key:value</code>, not <code>key</code>:<code>value</code></p>

<p>Also, this is Python3.x</p>

<p>Iterating over <code>.items()</code> and formatting differently then previous answers.</p>

<p>If your data is the following: <code>list</code> of <code>dict</code> objects then</p>

<pre><code>&gt;&gt;&gt; data = [{'key1':'value1', 'key2':'value2', 'key3':'value3'}] 
&gt;&gt;&gt; ', '.join('{0}:{1}'.format(*item) for item in my_dict.items() for my_dict in data)
'key2:value2, key3:value3, key1:value1'
</code></pre>

<p>If you data is the <code>list</code> of <code>set</code> objects then approach is simpler</p>

<pre><code>&gt;&gt;&gt; from itertools import chain
&gt;&gt;&gt; data = [{'key1:value1', 'key2:value2', 'key3:value3'}] 
&gt;&gt;&gt; ', '.join(chain.from_iterable(data))
'key1:value1, key2:value2, key3:value3'
</code></pre>

<p><strong>UPD</strong> </p>

<p>NOTE: order can be changed, because <code>set</code> and <code>dict</code> objects are not ordered.</p>

python regex string python-3.x