for(each) element aliasing
Reinhold Birkenfeld
reinhold-birkenfeld-nospam at wolke7.net
Mon Nov 22 11:58:03 EST 2004
Will McGugan wrote:
> Matija Papec wrote:
>> I know how to alter the list via list indicies but I would like to know if
>> there is posibility to write in Python something like:
>>
>> my @arr = 1..3;
>> for my $element (@arr) {
>> $element *= 2;
>> }
>> print "@arr\n";
>>
>> and get the result
>> -------
>> 2 4 6
>>
>>
>
> Something like this?
>
> arr= range(1,4)
> for index, value in enumerate( arr):
> arr[index]*= 2
But for this you won't need enumerate:
One of
for index in range(len(arr)):
for index in xrange(len(arr)):
is sufficient.
Reinhold
--
[Windows ist wie] die Bahn: Man muss sich um nichts kuemmern, zahlt fuer
jede Kleinigkeit einen Aufpreis, der Service ist mies, Fremde koennen
jederzeit einsteigen, es ist unflexibel und zu allen anderen Verkehrs-
mitteln inkompatibel. -- Florian Diesch in dcoulm
More information about the Python-list
mailing list