newbie-question about a list

Bengt Richter bokr at
Sat Nov 19 17:01:42 CET 2005

On 19 Nov 2005 07:06:30 -0800, bobueland at wrote:

>I've seen this construct in a script
>>>> [x.capitalize() for x in ['a','b', 'c']]
>['A', 'B', 'C']
>I tried another myself
>>>> [x+1 for x in [1,2,3]]
>[2, 3, 4]
>Apparently you can do
>[function(x) for x in list]
>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.
It's called a list comprehension. You can find that term in various indices
of the various docs. In a minute I found these. I'm sure there's more if
you google.

Bengt Richter

More information about the Python-list mailing list