c[:]()
Erik Max Francis
max at alcyone.com
Tue Jun 5 23:37:50 EDT 2007
Steven D'Aprano wrote:
> On Tue, 05 Jun 2007 18:26:50 -0400, Terry Reedy wrote:
>
>> "Warren Stringer" <warren at muse.com> wrote in message
>> news:015701c7a7a4$584fac00$240110ac at Muse... | I am porting code that
>> only uses this form | a[:4]b()
>> |
>> | Which translates to:
>> |
>> | for i in range(4):
>> | a[i].b()
>>
>> Or, more directly and perhaps more efficiently:
>>
>> for e in a[:4]: e.b()
>
> I'm thinking that is more efficient only because four is a small number.
> If you wanted to iterate over the first 2**22 items in a list of 2**22+1
> items, making a copy of the sub-list first would probably be a bad idea :)
Then again, in that case, so would making a list of the indices with
`range`, which is what the original poster was suggesting.
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
To endure what is unendurable is true endurance.
-- (a Japanese proverb)
More information about the Python-list
mailing list