quick beginners List comprehension question
Philip Semanchuk
philip at semanchuk.com
Wed Jan 21 12:26:32 EST 2009
On Jan 21, 2009, at 11:52 AM, Lou Pecora wrote:
> In article <mailman.7691.1232554737.3487.python-list at python.org>,
> Philip Semanchuk <philip at semanchuk.com> wrote:
>
>>
>> Other answers have been good; to them I'll add the comment that list
>> comprehensions are for *constructing* lists, not manipulating the
>> elements thereof.
>>
>> HTH
>> Philip
>
>
> Well this seems to work just fine. What am I missing:
>
> A=[1,2,3]
> print A
> A=[2*a for a in A]
> print A
You haven't manipulated the list A, you've simply overwritten it with
a new list.
More information about the Python-list
mailing list