printing tab-separated values of a list

Question:

Here’s my current code:

print(list[0], list[1], list[2], list[3], list[4], sep = 't')

I’d like to write it better. But

print('t'.join(list))

won’t work because list elements may numbers, other lists, etc., so join would complain.

Asked By: max

||

Answers:

print('t'.join(map(str,list)))
Answered By: fabrizioM
print(*list, sep='t')

Note that you shouldn’t use the word list as a variable name, since it’s the name of a builtin type.

Answered By: Glenn Maynard
print('t'.join([str(x) for x in list]))
Answered By: cred
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.