这是我的旧列表代码:
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>')
这是我的新清单:
hello2= ['bonjour','kiss']
预期输出:
<table>
<tr><td>hi</td><td>1</td><td>bonjour</td></tr>
<tr><td>hello</td><td>3</td><td>kiss</td></tr>
</table>