Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6814599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:42:28+00:00 2026-05-26T20:42:28+00:00

The signature for map is map(function, iterable[, iterables[, …]]) In Python 2.x if function

  • 0

The signature for map is

map(function, iterable[, iterables[, ...]])

In Python 2.x if function is None identity is assumed, and short iterables are padded with ‘None’ to the length of the longest iterable.

In Python 3.x if function is None you eventually get an exception:

TypeError: 'NoneType' object is not callable

and all iterables are trimmed to the length of the shortest one.

That’s a couple of pretty drastic changes. How do I get 2.x semantics back?

Oh, and it now returns an iterator instead of a list, but I’m okay with that change. 😉


This is useful for cases where you don’t know ahead of time which function, if any, will be applied — just because you aren’t actually transforming the iterable doesn’t mean you don’t want its contents.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:42:29+00:00Added an answer on May 26, 2026 at 8:42 pm

    You must roll your own — but it’s easy:

    from itertools import zip_longest, starmap
    
    def map2x(func, *iterables):
        if len(iterables) == 1:
            zipped = list(iterables[0])
        else:
            zipped = zip_longest(*iterables)
        if func is None:
            return zipped
        return starmap(func, zipped)
    

    A simple example:

    a=['a1']
    b=['b1','b2','b3']
    c=['c1','c2']
    
    print(list(map2x(None, a, b, c)))
    

    which gives us:

    [('a1', 'b1', 'c1'), (None, 'b2', 'c2'), (None, 'b3', None)]
    

    If you have only one iterable, like:

    map(None, 'hello world')
    

    Then simply replace that with:

    list('hello world')
    

    Update:

    My original answer here didn’t work if you called map() with None as function and only one iterable. That’s because nobody does that, since then you can just as well just use list(iterable). But I added the handling of that case anyway, by popular request. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm passing around a partially applied function. The full signature is: import Data.Map as
The method signature for Date.TryParse is: Public Shared Function TryParseExact ( _ s As
I have this function signature I have to match typedef int (*lua_CFunction) (lua_State *L);//target
The lookup function in Data.Map and Data.IntMap currently return values wrapped in Maybe with
We have a petition and each petition signature goes on a google map as
Is it possible to have a TLD map to the following function: public static
I need a recursive function, that would print a class signature, including class name
I have a function which signature is String -> String -> IO (Maybe String)
The signature of TraversableLike.flatMap is as follows: def flatMap[B, Th](f : (A) => Traversable[B])(implicit
The signature of the hashCode() method is public int hashCode(){ return x; } in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.