Efficient way to break up a list into two pieces

MRAB python at mrabarnett.plus.com
Sun Feb 21 05:37:47 CET 2010


Steven D'Aprano wrote:
[snip]
> I'm sympathetic to your concern: I've often felt offended that doing 
> something like this:
> 
> x = SomeReallyBigListOrString
> for item in x[1:]:
>     process(item)
> 
> has to copy the entire list or string (less the first item). But 
> honestly, I've never found a situation where it actually mattered.
> 
[snip]
Could lists gain an .items() method with start and end positions? I was
thinking that it would be a 'view', like with dicts in Python 3. Of
course, that would only be worthwhile with very long lists:

x = SomeReallyBigListOrString
for item in x.items(1):
     process(item)



More information about the Python-list mailing list