Try the following:
L = [['tables', 1, 2], ['ladders', 2, 5], ['chairs', 2]] for el in L: print('{0} {1}'.format(el[0],', '.join(str(i) for i in el[1:])))
Output:
tables 1, 2 ladders 2, 5 chairs 2
{0} {1}
is the output line in which
{0}
is equal to el[0]
, which is equal to 'tables'
, 'ladders'
, ...
{1}
equals ', '.join(str(i) for i in el[1:])
and ', '.join(str(i) for i in el[1:])
combines each element in the list of the following: [1,2]
, [2,5]
, ... with ', '
as a separator.
str(i) for i in el[1:]
used to convert each integer to a string before joining.
ovgolovin
source share