473,811 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mapping None. Why?


Iam wondering why the peculiar behavior of map when the function in
given as None:

Help on built-in function map in module __builtin__:

map(...)
map(function, sequence[, sequence, ...]) -list

Return a list of the results of applying the function to the items
of
the argument sequence(s). If more than one sequence is given, the
function is called with an argument list consisting of the
corresponding
item of each sequence, substituting None for missing values when
not all
sequences have the same length. If the function is None, return a
list of
the items of the sequence (or a list of tuples if more than one
sequence).
It seems as the action whith none is the same as using a function of
lambda *x: x
As in the following example:
>>l1 = 'asdf'
l2 = 'qwertyuip'
l3 = range(3)
l1,l2,l3
('asdf', 'qwertyuip', [0, 1, 2])
>>map(lambda *x: x, l1,l2,l3) == map(None, l1,l2,l3)
True
>>>

On looking up map on Wikipedia there is no mention of this special
behaviour,
So my question is why?

Thanks, Paddy.

Jun 27 '08
15 1385
On Jun 12, 9:36 pm, "Terry Reedy" <tjre...@udel.e duwrote:
"Paddy" <paddy3...@goog lemail.comwrote in message

news:a8******** *************** ***********@27g 2000hsf.googleg roups.com...
|
| Iam wondering why the peculiar behavior of map when the function in
| given as None:

The 'peculiar behavior' is the same as zip (except for padding short
iterators versus truncating long iterators. Map was added years before
zip. After that, map(None,...) was kept for back compatibility.

In 3.0, the doc for map is
"Return an iterator that applies function to every item of iterable,
yielding the results. If additional iterable arguments are passed, function
must take that many arguments and is applied to the items from all
iterables in parallel. With multiple iterables, the iterator stops when the
shortest iterable is exhausted."

Using a map defined with None raises
TypeError: 'NoneType' object is not callable

tjr
I really should get into the habit of reading the 3.0 docs before
asking questions :-)

My original question came about after answering this query:
http://gmcnaughton.livejournal.com/2...d=70451#t70451
- Paddy.
Jun 27 '08 #11
On Thu, 12 Jun 2008 12:05:02 -0700 (PDT), Paddy
<pa*******@goog lemail.comwrote :
>
Iam wondering why the peculiar behavior of map when the function in
given as None:
If you start with a value x and then apply no function
at all to it, what results is x.
>Help on built-in function map in module __builtin__:

map(...)
map(function, sequence[, sequence, ...]) -list

Return a list of the results of applying the function to the items
of
the argument sequence(s). If more than one sequence is given, the
function is called with an argument list consisting of the
correspondin g
item of each sequence, substituting None for missing values when
not all
sequences have the same length. If the function is None, return a
list of
the items of the sequence (or a list of tuples if more than one
sequence).
It seems as the action whith none is the same as using a function of
lambda *x: x
As in the following example:
>>>l1 = 'asdf'
l2 = 'qwertyuip'
l3 = range(3)
l1,l2,l3
('asdf', 'qwertyuip', [0, 1, 2])
>>>map(lambda *x: x, l1,l2,l3) == map(None, l1,l2,l3)
True
>>>>


On looking up map on Wikipedia there is no mention of this special
behaviour,
So my question is why?

Thanks, Paddy.
David C. Ullrich
Jun 27 '08 #12
On Jun 13, 12:49 pm, David C. Ullrich <dullr...@spryn et.comwrote:
On Thu, 12 Jun 2008 12:05:02 -0700 (PDT), Paddy

<paddy3...@goog lemail.comwrote :
Iam wondering why the peculiar behavior of map when the function in
given as None:

If you start with a value x and then apply no function
at all to it, what results is x.

David C. Ullrich
True, but None is not a function. It's a sentinel value to turn on the
functionality.

- Paddy.
Jun 27 '08 #13
In article
<d5************ *************** *******@j22g200 0hsf.googlegrou ps.com>,
Paddy <pa*******@goog lemail.comwrote :
On Jun 13, 12:49 pm, David C. Ullrich <dullr...@spryn et.comwrote:
On Thu, 12 Jun 2008 12:05:02 -0700 (PDT), Paddy

<paddy3...@goog lemail.comwrote :
>Iam wondering why the peculiar behavior of map when the function in
>given as None:
If you start with a value x and then apply no function
at all to it, what results is x.

David C. Ullrich

True, but None is not a function. It's a sentinel value to turn on the
functionality.
Uh, thanks. I think I knew that - I was just suggesting why
the way map works makes sense.
- Paddy.
--
David C. Ullrich
Jun 27 '08 #14

"David C. Ullrich" <du******@spryn et.comwrote in message
news:du******** *************** *****@text.giga news.com...
| In article
| <d5************ *************** *******@j22g200 0hsf.googlegrou ps.com>,
| Paddy <pa*******@goog lemail.comwrote :
|
| True, but None is not a function. It's a sentinel value to turn on the
| functionality.
|
| Uh, thanks. I think I knew that - I was just suggesting why
| the way map works makes sense.

filter(None, iterable) works the same way: None-identity function,
The immediate reason is the Python has no builtin id().
But apparently there is also historical precedent in the functional
community for this convention.

Jun 27 '08 #15
On Fri, Jun 13, 2008 at 2:00 PM, Terry Reedy <tj*****@udel.e duwrote:
filter(None, iterable) works the same way: None-identity function,
The immediate reason is the Python has no builtin id().
But apparently there is also historical precedent in the functional
community for this convention.
Another way of viewing it is that filter(None, iterable) applies no
function at all before testing the truth values, which does make some
sense. With map, however, this is not strictly true.
Jun 27 '08 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1907
by: max | last post by:
I am trying to use a sdk to access quickbooks, the sdk provided a COM interface and I think it installed the com server files/dlls. A VB code example is provided, but I can't figure out how to map "Dim sessionManager As New QBFC2_1Lib.QBSessionManager" into a corresponding Python statement, when I try obj = win32com.Client.Dispatch("QBFC2_1Lib.QBSessionManager") I get traceback Shown below. I have been able to run makepy and it...
9
2479
by: Jerry Sievers | last post by:
Fellow Pythonists; I am totally puzzled on the use of slicing on mapping types and especially unsure on use of the Ellipsis... and slicing syntax that has two or more groups seperated by comma. I am referring to (from the manual); Slice objects Slice objects are used to represent slices when extended
1
1719
by: none | last post by:
Hi, I'm trying to establish table mappings, and I've hit a snag. At the point to where I try to fill the schema (DB_adapter.FillSchema), I get an exception, and the message is as follows: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Invalid column name 'Unique_ref'. Invalid column name 'ID_string'. Invalid column name 'Sequence'.
8
1380
by: micklee74 | last post by:
hi i wish to map None or "None" values to "". eg a = None b = None c = "None" map( <something> , if i in ("None",None) ]) I can't seem to find a way to put all values to "". Can anyone help?
3
1305
by: Lee Sander | last post by:
hi, I have the following problem which is turning out to be non-trivial. I realize that this is not exactly a python problem but more of an algorithm problem -- but I post it here because I want to implement this in python. I want to write a code that given an interval (integer tuple: start,stop) will find which other interval it matches to. Here is an example,
0
9731
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5556
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4342
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.