You could use a for loop, to print each nested list one by one:
>>> for data2 in list_data2:
print(data2)
['Sid', 9, 8, 7]
['Tony', 9, 6, 4]
['Charlie', 4, 2, 1]
but if you want to format it in a nicer way, you could pass multiple arguments to print, like print(data2[0], data2[1], data2[2], data2[3])
, or in short, using print(*data2)
:
>>> for data2 in list_data2:
print(*data2)
Sid 9 8 7
Tony 9 6 4
Charlie 4 2 1
The default separator when using print with multiple arguments is ' '
, but you can change that using the keyword argument sep
:
>>> for data2 in list_data2:
print(*data2, sep='\t')
Sid 9 8 7
Tony 9 6 4
Charlie 4 2 1
Note that the tab width is dependent on your terminal settings. You can achieve a similar effect using a format string with fixed width columns (filled by space characters):
>>> for data2 in list_data2:
print('%-12s %3d %3d %3d' % tuple(data2))
Sid 9 8 7
Tony 9 6 4
Charlie 4 2 1
However, this printf-like % syntax is deprecated, and you should use the new .format() method of str
:
>>> for data2 in list_data2:
print('{0:<12} {1:3d} {2:3d} {3:3d}'.format(*data2))
Sid 9 8 7
Tony 9 6 4
Charlie 4 2 1
(see https://docs.python.org/2/library/string.html#format-examples for more examples)