slice notation as values?
bonono at gmail.com
bonono at gmail.com
Mon Dec 12 05:20:54 EST 2005
More information about the Python-list mailing list
Mon Dec 12 05:20:54 EST 2005
- Previous message (by thread): slice notation as values?
- Next message (by thread): Problem with Lexical Scope
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Antoon Pardon wrote: > Suppose I have a list with 10 000 elements and I want > the sum of the first 100, the sum of the second 100 ... > > One way to do that would be: > > for i in xrange(0,10000,100): > sum(itertools.islice(lst, i, i+100)) > > But itertools.islice would each time start from the begining > of the list and iterate over i elements before giving 100 > elements to sum. Which would make this implementation O(n^2) > instead of O(n). Can you use iter for this situation ? a=iter(lst) for i in xrange(0,10000,100): sum(itertools.islice(a,100))
- Previous message (by thread): slice notation as values?
- Next message (by thread): Problem with Lexical Scope
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list