[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-04-02 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
resolution:  -> out of date
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-25 Thread Ezio Melotti

Ezio Melotti  added the comment:

Raymond, before porting you should check the typos reported in issue #7778.

--
dependencies: +Typo(s) in ``itertools`` documentation reST marker
nosy: +ezio.melotti
stage: needs patch -> commit review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-25 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

No problem.
Will forward port when I get a chance.

--
versions:  -Python 2.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-24 Thread Muhammad Alkarouri

Muhammad Alkarouri  added the comment:

Mea culpa. Not knowing the conventions here, I closed the ticket, which 
probably resulted in florent's feedback. I will leave you to it then.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-24 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

Remain calm.  I left the status as Open for a reason.  When I'm satisfied that 
people are reacting well to the new update, will port to other versions.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-24 Thread Florent Xicluna

Florent Xicluna  added the comment:

Changeset r77721 should be ported to trunk, and py3k probably.

--
nosy: +flox
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-24 Thread Jan Kaliszewski

Jan Kaliszewski  added the comment:

(sorry! typed into a wrong field)

--
nosy: +zuo
versions: +Python 2.6, Python 2.7, Python 3.2

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-24 Thread Jan Kaliszewski

Changes by Jan Kaliszewski :


--
title: dictview -> Doc for itertools recipe consume is complicated and less 
efficient

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-24 Thread Muhammad Alkarouri

Muhammad Alkarouri  added the comment:

Excellent solution and comments. Many thanks.

--
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-23 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

See r77721

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-23 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

Will switch to the version using next() instead of deque().

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-23 Thread Peter Otten

Peter Otten <__pete...@web.de> added the comment:

As noted on comp.lang.python the implementation can be simplified to

def consume(items, n):
next(islice(items, n, n), None)

When I suggested the above I wasn't aware that 

consume(items, None)

should exhaust the entire iterator. Unfortunately I've not found an elegant way 
to add that functionality.

--
nosy: +potten

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-23 Thread Georg Brandl

Changes by Georg Brandl :


--
assignee: georg.brandl -> rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-23 Thread Ezio Melotti

Changes by Ezio Melotti :


--
nosy: +rhettinger
priority:  -> normal
stage:  -> needs patch
versions: +Python 2.6, Python 2.7, Python 3.1, Python 3.2

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7764] Doc for itertools recipe consume is complicated and less efficient

2010-01-23 Thread Muhammad Alkarouri

New submission from Muhammad Alkarouri :

Based on the discussion at:
http://groups.google.co.uk/group/comp.lang.python/browse_thread/thread/c1ae3513a31eb63e/d0701a9902732c67?hl=en#d0701a9902732c67

In the documentation of itertools, one of the functions provided in the recipes 
section (10.7.3) is consume:

def consume(iterator, n):
"Advance the iterator n-steps ahead. If n is none, consume entirely."
collections.deque(islice(iterator, n), maxlen=0)

A clearer implementation is:

def consume(n, items):
if n == 0:
return
next(islice(items, n-1, None), None)

It uses no fancy tricks and is thus more suitable for a documentation. 
Moreover, the second implementation is actually more efficient. Some timings 
are provided in the thread linked above. As an example, here are the timings on 
my machine (Python 2.6.1, x86_64, OS X 10.6:

consume_deque #old implementation
10: 1.2913839817
   100: 3.18093585968
  1000: 21.6316840649

consume_forloop #using a straight for loop
10: 0.658184051514
   100: 2.85271406174
  1000: 24.6730420589

consume_islice #the suggested implementation
10: 0.688861131668
   100: 1.15058612823
  1000: 5.52356886864

The script computing these timings is attached. Thanks to Peter Otten for 
coming up both with the function and the timing script.

--
assignee: georg.brandl
components: Documentation
files: consume_timeit.py
messages: 98187
nosy: Muhammad.Alkarouri, georg.brandl
severity: normal
status: open
title: Doc for itertools recipe consume is complicated and less efficient
type: performance
Added file: http://bugs.python.org/file15978/consume_timeit.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com