Efficiently iterating over part of a list
Peter Otten
__peter__ at web.de
Fri Oct 13 04:05:39 EDT 2006
More information about the Python-list mailing list
Fri Oct 13 04:05:39 EDT 2006
- Previous message (by thread): Efficiently iterating over part of a list
- Next message (by thread): Using SVN with Python and .pyc files
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Steven D'Aprano wrote:
> Are there better or more Pythonic alternatives to this obvious C-like
> idiom?
>
> for i in range(1, len(alist)):
> x = alist[i]
For small start values you can use itertools.islice(), e. g:
for x in islice(alist, 1, None):
# use x
You'd have to time at what point the C-like idiom (which I would have no
qualms using throughout) becomes faster.
Peter
- Previous message (by thread): Efficiently iterating over part of a list
- Next message (by thread): Using SVN with Python and .pyc files
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list