似乎应该有一个更简单的方法来做到这一点:
header_line = [x for x in my_dict.keys()]
header_line.insert(0, "1st column\t2nd column")
header_line.append("note")
print "\t".join(map(str, header_line))
我天真地认为以下应该可以工作,但是在 header_line 上出现语法错误:
header_line = ["1st column", "2nd column", x for x in my_dict.keys(), "note"]
print "\t".join(map(str, header_line))