What's the difference?

Emile van Sebille emile at fenx.com
Thu Jun 10 17:19:45 EDT 2010


On 6/10/2010 1:47 PM Anthony Papillion said...
> Someone helped me with some code yesterday and I'm trying to
> understand it. The way they wrote it was
>
> subjects = (info[2] for info in items)
>
> Perhaps I'm not truly understanding what this does. Does this do
> anything different than if I wrote
>
> for info[2] in items
>     subject = info[2]
>

more like:

result = []
for info in items:
   result.append(info[2])

subjects =iter(result)

Emile




More information about the Python-list mailing list