[Python-bugs-list] [ python-Bugs-798473 ] inconsistent behavior of map and imap

SourceForge.net noreply at sourceforge.net
Mon Sep 1 16:44:28 EDT 2003


Bugs item #798473, was opened at 2003-09-01 19:41
Message generated for change (Comment added) made by quiver
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=798473&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Closed
Resolution: Wont Fix
Priority: 5
Submitted By: George Yoshida (quiver)
Assigned to: Nobody/Anonymous (nobody)
Summary: inconsistent behavior of map and imap

Initial Comment:
If you pass sequences to map and imap and
the sizes of sequences are not equal,
map and imap don't behave the same way.

The code below is a simple example.
The size of seq1 and seq2 is not equal.

>>> seq1 = [0, 1, 2]
>>> seq2 = ['a', 'b']
>>> import itertools
>>> for x,y in map(None, seq1, seq2):print x,y
...
0 a
1 b
2 None
>>> for x,y in itertools.imap(None, seq1, 
seq2):print x,y
...
0 a
1 b

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

>Comment By: George Yoshida (quiver)
Date: 2003-09-02 07:44

Message:
Logged In: YES 
user_id=671362

I should have read the Library Reference more carefully.
It documents the difference of map and imap in detail.

Thanks for taking time off to reply to my post.

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-09-02 01:38

Message:
Logged In: YES 
user_id=80475

This difference was intended and is considered a feature:

1. It allows imap() to be used with infinite iterators.

2. None fill-in is rarely useful (how many functions respond 
well to having arguments suddendy switch to None?).

3. If needed, None padding is easy to add:
     for x,y in imap(None, seq1, chain(seq2, repeat(None)))


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

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



More information about the Python-bugs-list mailing list