How to change list into HTML table ? (Python) -


this question has answer here:

this have done when there no html codes

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

and want change html table , have try far, still doesn't work

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

you can use collections.counter count occurrences in list, use information create html table. try this:

from collections import counter, defaultdict  hello = ["hello","hi","hello","hello"] counter= counter(hello) bye = defaultdict(int) print"<table>" word in counter.keys():     print "<tr>"     print "<td>" + str(word) + ":" + str(counter[word]) + "</td>"     print "</tr>"     bye[word] = counter[word] print"</table>" 

the output of code (you can change format if want):

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

hope you!


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -