[Python-bugs-list] [ python-Bugs-825247 ] Itertools imap and izip boundary cases

SourceForge.net noreply at sourceforge.net
Thu Oct 16 21:55:27 EDT 2003


Bugs item #825247, was opened at 2003-10-17 01:55
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=825247&group_id=5470

Category: Extension Modules
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Mark Dickinson (marketdickinson)
Assigned to: Nobody/Anonymous (nobody)
Summary: Itertools imap and izip boundary cases

Initial Comment:
It appears that itertools.imap cannot be applied to a
function f of
zero arguments: imap(f) raises a TypeError with the
message "imap()
must have at least two arguments".  Is there a reason
for this
restriction?  There's a logical and natural definition
for imap(f),
which fits with all the current documentation: it
should be an
iterator returning the sequence f(), f(), f(), .... 
Not only is this
natural but it's also useful: for example, imap(random)
is a handy way
to write down an iterator that returns a succession of
random floats
in [0, 1).  Is there a reason for treating functions
with zero
arguments differently from functions with one or more
arguments?

I'd also argue that the result of izip() is incorrect:
if it's going
to work according to the same rules as other calls of
izip, it should
return an infinite list of empty tuples; that is, it
should be
equivalent to repeat(()).  As the docstring states, the
.next() method
should continue until one of the iterables is
exhausted; with no
iterables, this never happens, so a strict logical
reading of this
statement is that the .next() method of izip() should
continue
indefinitely.  This definition of izip() also ensures
that natural
laws like

imap(f, *args) = starmap(f, izip(*args)) 

don't break in the boundary case (at least, given my
proposed
definition of imap(f) above).

(The above changes can be effected by simply removing 7
lines from the itertools.c source code.)



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=825247&group_id=5470



More information about the Python-bugs-list mailing list