python create html table from dict
<p>I´m just starting learning python and therefore like to create a html table based on filenames. 
Imaging following files</p>

<pre><code>apple.good.2.svg
apple.good.1.svg
banana.1.ugly.svg
banana.bad.2.svg
kiwi.good.svg
</code></pre>

<p>The kind of object is always the first part (before the first dot) the quality property is somewhere in the name.</p>

<p>My resulting table should look like this:</p>

<pre><code>Object Name    |       good       |       bad       |       ugly
-------------------------------------------------------------------------
apple          | apple.good.1.svg |
               | apple.good.2.svg |
-------------------------------------------------------------------------
banana         |                  | banana.bad.2.svg | banana.1.ugly.svg
-------------------------------------------------------------------------
kiwi           | kiwi.good.svg
-------------------------------------------------------------------------
</code></pre>

<p>This is what I did so far</p>

<pre><code>#!/usr/bin/python
import glob
from collections import defaultdict

fileNames = defaultdict(list)

# fill sorted list of tables based on svg filenames
svgFiles = sorted(glob.glob('*.svg'))
for s in svgFiles: 
    fileNames[s.split('.', 1)[0]].append(s)        

# write to html
html = '&lt;html&gt;&lt;table border="1"&gt;&lt;tr&gt;&lt;th&gt;A&lt;/th&gt;&lt;th&gt;' + '&lt;/th&gt;&lt;th&gt;'.join(dict(fileNames).keys()) + '&lt;/th&gt;&lt;/tr&gt;'

for row in zip(*dict(fileNames).values()):
    html += '&lt;tr&gt;&lt;td&gt;Object Name&lt;/td&gt;&lt;td&gt;' + '&lt;/td&gt;&lt;td&gt;'.join(row) + '&lt;/td&gt;&lt;/tr&gt;'

html += '&lt;/table&gt;&lt;/html&gt;'

file_ = open('result.html', 'w')
file_.write(html)
file_.close()
</code></pre>

<p>I managed to read the files sorted in a dict:</p>

<pre><code>{'kiwi': ['kiwi.good.svg'], 'apple': ['apple.good.2.svg', 'apple.good.1.svg'], 'banana': ['banana.1.ugly.svg', 'banana.bad.2.svg']}
</code></pre>

<p>But fail by generating the html table. </p>

<p><a href="https://i.stack.imgur.com/E79th.png" rel="noreferrer"><img src="https://i.stack.imgur.com/E79th.png" alt="enter image description here"></a></p>

<p>How can I build the html table as shown above? Where Objects are written to the first first column of a row and the filename in columns depending on their quality property?</p>