![]() |
The Demise of lambda, map, filter and reduce
hydroxide mentioned this blog from Guido himself:
http://www.artima.com/weblogs/viewpost.jsp?thread=98196 Very interesting reading material. Is anyone going to miss these functions? Also, does anyone have additional info on the upcoming Python 3.0? |
The functionality of filter and map is the same as list comprehensions, so I don't think there's much loss there. I've never found a use for reduce in any program I've devised, and lambda is rather un-pythonic.
This said, I wish Python had some syntactic sugar for: :
def anon(...)::
keyword function: |
Where `function(anon)` does what exactly?
I like map for the speedups you can get by pushing the loop into C. Other than for that, it's not of much use now the list comps are around and more readable. Same goes for the other functions for me really. |
Talking about syntactic sugar, a save and intelligent input for numbers would be nice. Something that accepts only a numeric value, and does not allow some clown to erase your hard disk.
|
Quote:
:
def print_output(func)::
def print_output(func): |
If you need to do that, you should restructure your program so you're not passing function pointers when you don't have to.
|
I found this sweet little code on the web somewhere. It contains both reduce() and lambda. Any idea how to rewrite this without those two functions?
:
# note reduce() and lambda will be dropped with Python3.0 |
Quote:
Quote:
Quote:
|
That's a pretty sweet function and a concise one at that, but profusely unreadable. A balance really is necessary.
Another addition to (the next release, I believe) of Python is conditional expressions in the form of :
x if condition else y |
You mean a ternary operator? Finally! The and-or hack doesn't quite cut it :p
Certainly list comprehensions can replace map and filter, but I personally think :
[i for i in l if p(i)]:
map(p, l) |
| All times are GMT -5. The time now is 12:31 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC