How to change list into HTML table ? (Python)
Question: This is what I have done when there is no HTML codes

    
    
    from collections import defaultdict
    
    hello = ["hello","hi","hello","hello"]
    def test(string):
        bye = defaultdict(int)
        for i in hello:
            bye[i]+=1
        return bye
    

And i want to change this to html table and This is what I have try so far,
but it still doesn't work

    
    
     def test2(string):
        bye= defaultdict(int)
        print"<table>"
        for i in hello:
            print "<tr>"
            print "<td>"+bye[i]= bye[i] +1+"</td>"
            print "</tr>"
        print"</table>"
        return bye
    

​


Answer: 
    from collections import defaultdict
    
    hello = ["hello","hi","hello","hello"]
    
    def test2(strList):
      d = defaultdict(int)
      for k in strList:
        d[k] += 1
      print('<table>')
      for i in d.items():
        print('<tr><td>{0[0]}</td><td>{0[1]}</td></tr>'.format(i))
      print('</table>')
    
    test2(hello)
    

**Output**

    
    
    <table>
      <tr><td>hi</td><td>1</td></tr>
      <tr><td>hello</td><td>3</td></tr>
    </table>
    

