![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
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?
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
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(...):
# code
function(anon)keyword function: # code |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
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.
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#5 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
Quote:
def print_output(func):
print func(10)
def increment(x):
return x + 1
print_output(increment)def print_output(func):
print func(10)
use x in print_output:
return x + 1 |
|
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
If you need to do that, you should restructure your program so you're not passing function pointers when you don't have to.
|
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
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
def wrap(text, width):
"""
A word-wrap function that preserves existing line breaks
and most spaces in the text. Expects that existing line
breaks are linux style newlines (\n).
"""
return reduce(lambda line, word, width=width: '%s%s%s' %
(line,
' \n'[(len(line)-line.rfind('\n')-1
+ len(word.split('\n',1)[0]
) >= width)],
word),
text.split(' ')
)
# 2 very long lines separated by a blank line
msg = """Arthur: "The Lady of the Lake, her arm clad in the purest \
shimmering samite, held aloft Excalibur from the bosom of the water, \
signifying by Divine Providence that I, Arthur, was to carry \
Excalibur. That is why I am your king!"
Smarty: "Listen. Strange women lying in ponds distributing swords is \
no basis for a system of government. Supreme executive power derives \
from a mandate from the masses, not from some farcical aquatic \
ceremony!\""""
# example: make it fit in 40 columns
print wrap(msg,40)
# result is below, note Smarty is now S,arty (why?)
"""
Arthur: "The Lady of the Lake, her arm
clad in the purest shimmering samite,
held aloft Excalibur from the bosom of
the water, signifying by Divine
Providence that I, Arthur, was to carry
Excalibur. That is why I am your king!"
S,arty: "Listen. Strange women lying in
ponds distributing swords is no basis
for a system of government. Supreme
executive power derives from a mandate
from the masses, not from some farcical
aquatic ceremony!"
"""
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#8 | |||
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
Quote:
Quote:
Quote:
|
|||
|
|
|
|
|
#9 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Dec 2005
Posts: 118
Rep Power: 0
![]() |
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) |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|