【发布时间】:2013-05-07 07:55:48
【问题描述】:
这是我在没有HTML代码时所做的
from collections import defaultdict
hello = ["hello","hi","hello","hello"]
def test(string):
bye = defaultdict(int)
for i in hello:
bye[i]+=1
return bye
我想将其更改为 html 表,这是我迄今为止尝试过的,但它仍然不起作用
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
【问题讨论】:
-
还是不行。>回溯(最近一次调用最后一次): print "
"+bye[i]= bye[i] +1+" " ^ SyntaxError:语法无效 -
你期望的输出是什么?
-
@AshwiniChaudhary 我想要与第一个相同的输出,但添加了 HTML 代码
-
你为什么在函数完成之前返回?
-
@ErikaSawajiri 第一个和第二个是有区别的,你没有在第一个打印任何东西。发布预期的 html 输出以明确问题。