String building using join
Alex Willmer
alex at moreati.org.uk
Sun Jan 2 13:11:50 EST 2011
On Sunday, January 2, 2011 5:43:38 PM UTC, gervaz wrote:
> Sorry, but it does not work
>
> >>> def prg3(l):
> ... return "\n".join([x for x in l if x])
> ...
> >>> prg3(t)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "<stdin>", line 2, in prg3
> TypeError: sequence item 0: expected str instance, Test found
def prg3(l):
return '\n'.join([str(x) for x in l if x])
That should do it
More information about the Python-list
mailing list