473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

filter and map / deprecated?

I read in PEP 279 the following comment by GvR:

"filter and map should die and be subsumed into list
comprehensions, not grow more variants."

Actually, I am using 'filter' and 'map' a lot in my scripts
(not really because they are necessary, but more because I
like them). Should I avoid the usage of 'filter' and 'map'
in the future? The above comment by GvR makes me a little
bit afraid that they will become deprecated one day and that
I will have to change many of my scripts then.

--
mailto: logan@phreaker(NoSpam).net

Jul 18 '05 #1
5 5441

"Logan" <lo***@phreaker.nospam> wrote in message news:pa****************************@phreaker.nospa m...
I read in PEP 279 the following comment by GvR:

"filter and map should die and be subsumed into list
comprehensions, not grow more variants."

Actually, I am using 'filter' and 'map' a lot in my scripts
(not really because they are necessary, but more because I
like them). Should I avoid the usage of 'filter' and 'map'
in the future? The above comment by GvR makes me a little
bit afraid that they will become deprecated one day and that
I will have to change many of my scripts then.


You will have to port and and test your scripts on the new Python.
You aren't going to use them untested, are you? In case of
filter & map you will just have to (my guess) insert:
from legacy import filter, map
Using filter & map these days is discouraged, use itertools
module.

Anyway I think before they disappear they should be removed
from documentation and _books_ first. I mean old books should
become obsolete, new books and documentation should briefly
mention them in the legacy chapter. These are should be no
trace of them in the main chapters. And then the functions can
be actually removed from the Python core. I beleive this is the
least painful way to get rid of them. The cost of keeping them
in the core is very low, the main problem is documentation.
So the process of deprecitation should focus on the documentation.

-- Serge.
Jul 18 '05 #2

"Logan" <lo***@phreaker.nospam> wrote in message
news:pa****************************@phreaker.nospa m...
I read in PEP 279 the following comment by GvR:

"filter and map should die and be subsumed into list
comprehensions, not grow more variants."

Actually, I am using 'filter' and 'map' a lot in my scripts
(not really because they are necessary, but more because I
like them). Should I avoid the usage of 'filter' and 'map'
in the future? The above comment by GvR makes me a little
bit afraid that they will become deprecated one day and that
I will have to change many of my scripts then.
My understanding is that they are on the list of functions
to go away in 3.0. Guido would like to get rid of all five
of the "functional programming" mechanisms. So far,
filter, map and apply have acceptable substitutes, and
the arm waving brigade is claiming that the new sum()
function will handle all "real" use cases for reduce. (You
can tell I don't agree, but that doesn't seem to be
relevant.) Lambda is the odd man out at this point.
I believe it's waiting on an acceptable syntax
for blocks, which seems to be very hard to do.

John Roth
--
mailto: logan@phreaker(NoSpam).net

Jul 18 '05 #3
Also, I suppose if you were *really* in a rush and wanted to get old code
working, then all you'd have to do is add something like this to it:

def map( func, seq ): return [ func(x) for x in seq ]
def filter( func, seq ): return [ x for x in seq if func(x) ]

This will probably be less efficient than Serge's solution. It is probably
also better to have that self-documenting "from legacy ..." in there, to
boot.

I think after a using list comprehensions for a while, they become a lot
more comfortable though, so it is not such a bad thing to develop the habit
of using them instead. Then, in the fullness of time, map() and filter()
will begin to look funny.
Jul 18 '05 #4

"Logan" <lo***@phreaker.nospam> wrote in message
news:pa****************************@phreaker.nospa m...
I read in PEP 279 the following comment by GvR:

"filter and map should die and be subsumed into list comprehensions, not grow more variants."

Actually, I am using 'filter' and 'map' a lot in my scripts (not really because they are necessary, but more because I like them). Should I avoid the usage of 'filter' and 'map' in the future? The above comment by GvR makes me a little bit afraid that they will become deprecated one day and that I will have to change many of my scripts then.


Removing filter, map, etc, totally would be a
contentious and controversial move and would make
many people unhappy. I do not anticipate it.

It has been proposed on PyDev that they be moved
to a 'functional' module (name not yet decided),
perhaps with other stuff added, and I believe that
Guido said he would be amenable to that. This I
do anticipate. The threshhold for being in a
module is much lower than the threshhold for being
added to and eventually for remaining in the
builtins.

So I would continue with your preference with the
expectation that some years from now you would
have to run 2.x scripts through a search and
replace script to run them with Python 3. But I
expect that will be true anyway to cope with other
changes. I also expect that people will use
2.final for years after the arrival of 3.0 (Just
as 1.5.2 is still in use today.)

Terry J. Reedy
Jul 18 '05 #5
> I read in PEP 279 the following comment by GvR:

"filter and map should die and be subsumed into list
comprehensions, not grow more variants."

Actually, I am using 'filter' and 'map' a lot in my scripts
(not really because they are necessary, but more because I
like them). Should I avoid the usage of 'filter' and 'map'
in the future? The above comment by GvR makes me a little
bit afraid that they will become deprecated one day and that
I will have to change many of my scripts then.


Until Py3.0, we are shying away from deprecating things.
apply(), buffer(), coerce(), and intern() were moved to a
separate page in the docs for obsolete or non-essential stuff
but there are no deprecations.

The itertools variants of filter and map are proving to be
popular and will likely be around for a long time. I suggest
using them instead of the builtins since they are memory friendly
and scale-up nicely.
Raymond Hettinger
Jul 18 '05 #6

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

Similar topics

8
by: Uwe Mayer | last post by:
Hi, Why is the UserDict module is deprecated after Python 2.2. The application of it I have in mind is, i.e. multiple inheritance from "file" and "dic" - which is not possible. If I used...
2
by: gf gf | last post by:
I read that lower() is deprecated. Unfortunately, I can't find the preferred way of lowercasing a string. What is it? Thanks PS Please cc me on all responses.
26
by: puzzled | last post by:
Okay, so my subject sounds a bit crass. As much as I'd like to totally embrace css and avoid "deprecated" usage, sometimes the deprecated stuff is so much easier and more effective. Plus, it at...
4
by: Lieven | last post by:
I'm trying to use is_sorted. When I do #include<algo.h>, I get: /usr/include/g++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated...
45
by: Matt Parkins | last post by:
Hi, (I realise this probably isn't precisely the right group for this - could someone direct me to the appropriate group to post this question? - thanks !) I'm using Visual C++ 2005 Express...
9
by: Robert | last post by:
Hi, Currently I am using argument.callee.caller.arguments to get the arguments of the caller function, but Firefox complains that arguments (of Function) is deprecated. Is there a way to get...
3
by: Ben Rush | last post by:
When I compile my solution I get the following output - NET 2003\Vc7\atlmfc\include\atlwin.h(2027) : warning C4995: 'wsprintf': name was marked as #pragma deprecated C:\Program Files\Microsoft...
3
by: Tony | last post by:
At http://www.quirksmode.org/js/placejs.html I found a discussion on how & where to place your javascript. Toward the bottom of the page, PPK has a section titled Deprecated: Direct JavaScripts,...
5
by: Scirious | last post by:
People, how many deprecated methods have really been removed and no longer exists? TIA, Scirious.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.