newbie-question about a list

Mike Meyer mwm at
Sun Nov 20 05:24:46 CET 2005

bobueland at writes:
> I've seen this construct in a script
>>>> [x.capitalize() for x in ['a','b', 'c']]
> ['A', 'B', 'C']
> I tried to find a description of this in "Library Reference" but
> couldn't find it. Could somebody direct me where this type of construct
> is described.

As others have pointed out, it's called a "list comprehension". But
it's syntax, so the proper place to look for it is the "Language
Reference", not the "Library Reference". Except in this case, the
language reference is fairly opaque, so you're better off using the
google references others have already provided.

You might also look for the related construct, "generator


Mike Meyer <mwm at>
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list