[Tutor] join question
Alan Gauld
alan.gauld at btinternet.com
Fri Oct 15 00:43:17 CEST 2010
"Roelof Wobben" <rwobben at hotmail.com> wrote
> print ''.join([zf.getinfo('%s.txt' % p).comment for p in zpp])
>
> So I thought that this would be the same :
>
> for p in zpp:
> test = zf.getinfo(p).comment
> print ''.join(test)
>
> But it seems not to work
>
> Can anyone explain why not ?
Because it's not the same. test in your version is only a single item.
In the original its a list of items. So to write similar code
explicitly you need:
lst = []
for p in zpp:
test = zf.getinfo(p).comment
lst.append(test)
print ''.join(lst)
HTH,
Alan G.
More information about the Tutor
mailing list