I want to print a table mixed with strings and floating point values โโas a printout of tab delimited output. Of course I can do this work:
>>> tab = [['a', 1], ['b', 2]] >>> for row in tab: ... out = "" ... for col in row: ... out = out + str(col) + "\t" ... print out.rstrip() ... a 1 b 2
But I have a feeling that there is a better way to do this in Python, at least for printing each row with the specified delimiter, if not the whole table. A little googling (from here ), and it's already shorter:
>>> for row in tab: ... print "\t".join([str(col) for col in row]) ... a 1 b 2
Is there an even better or more Python-ish way?
source share