for(each) element aliasing
Matija Papec
mpapec at yahoo.com
Mon Nov 22 13:18:43 EST 2004
X-Ftn-To: Jp Calderone
Jp Calderone <exarkun at divmod.com> wrote:
>> -------
>> 2 4 6
>
> No. Integers in Python are immutable. For lists of other things, mutation in-place (similar to the above example) is possible, but for integers and other immutable types, it is not. You may be interested in list comprehensions, though:
>
> arr = range(1, 4)
> arr[:] = [a * 2 for a in arr]
> print arr
I guess this works like "map" but "for" is more idimatic.
Thank you all for so quick responses. :)
--
Matija
More information about the Python-list
mailing list