[Tutor] join question

Hugo Arts hugo.yoshi at gmail.com
Thu Oct 14 16:08:50 CEST 2010


On Thu, Oct 14, 2010 at 3:50 PM, Roelof Wobben <rwobben at hotmail.com> wrote:
>
>
> Hello,
>
> I found this answer to a problem for me :
>
>
> print ''.join([zf.getinfo('%s.txt' % p).comment for p in zpp])
>

Look at the argument given to join here. It is a list comprehension.
The result of a list comprehension is a list. You're calling join
once, with a list as argument.

> So I thought that this would be the same :
>
> for p in zpp:
>      test = zf.getinfo(p).comment
>      print ''.join(test)
>

Now look at the argument to join again. It is not a list, but a single
element of a list. Also, you're calling join for every element,
instead of just once. That's not the same thing, is it?

> But it seems not to work
>
> Can anyone explain why not ?
>
> Roelof
>


More information about the Tutor mailing list