Re: flatten(), [was Re: map/filter/reduce/lambda opinions ...]

2005-07-07 Thread Tom Anderson
On Thu, 7 Jul 2005, Ron Adam wrote: Stian Søiland wrote: > Or what about a recursive generator? That's the sort of thing i like to see! Ok, lets see... I found a few problems with the testing (and corrected it) so the scores have changed. My sort in place routines were cheating because t

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Bengt Richter
On 7 Jul 2005 15:46:23 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote: >Steven D'Aprano wrote: > >> Put it this way: whenever I see a two-line def as above, I can't help >> feeling that it is a waste of a def. ("Somebody went to all the trouble >> to define a function for *that*?") Yet I would never

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Ron Adam
Reinhold Birkenfeld wrote: > Ron Adam wrote: > > >>Given the statement: >> >>a = None >> >>And the following are all true: >> >> a == None > > > Okay. > > >>(a) == (None) > > > Okay. > > >>(a) == () > > > Whoops! a (which is None) is equal to the empty tuple (which is not None)? It's

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Sion Arrowsmith
=?ISO-8859-2?Q?Pawe=B3?= Sakowski <[EMAIL PROTECTED]> wrote: ll=[[1,2],[3,4,5],[6]] sum(ll,[]) >[1, 2, 3, 4, 5, 6] That's a great argument for list.__add__ having the semantics of extend rather than append 8-) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Fra

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Duncan Booth
Steven D'Aprano wrote: > Put it this way: whenever I see a two-line def as above, I can't help > feeling that it is a waste of a def. ("Somebody went to all the trouble > to define a function for *that*?") Yet I would never think the same about > a lambda -- lambdas just feel like they should be l

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Steven D'Aprano
hons" >> >> > No, that is approaching a reasonable use of lambda, however I would still > be inclined to write it with functions. e.g. > >def one(noun): >return noun > >def two(noun): >return noun+'s' > >def

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Paweł Sakowski
Tom Anderson wrote: > def flatten(ll): > return reduce(lambda a, l: a.extend(l), ll, []) > > How would one do that as a list comp, by the way? I'm really not very good > with them yet. Not really a list-comprehension based solution, but I think what you want is >>> ll=[[1,2],[3,4,5],[6]] >>> su

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-07 Thread Chris Rebert (cybercobra)
Agreed, I dislike map and its ilk as well. However, they are handy in some cases. I particularly like the way Ruby deals with this problem. Instead of all these functions, internal iterators and true anonymous blocks are used. Case in point: def gt_than_5(obj): return obj > 5 results = fil

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Duncan Booth
Steven D'Aprano wrote: > This is something I've never understood. Why is it bad > form to assign an "anonymous function" (an object) to a > name? Because it obfuscates your code for no benefit. You should avoid making it hard for others to read your code (and 'others' includes yourself in the

Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Steven D'Aprano
Steven Bethard wrote: > If you're really afraid of two lines, write it as: > > def r(): randint(1, 100) > > This is definitely a bad case for an anonymous function because it's not > anonymous! You give it a name, r. This is something I've never understood. Why is it bad form to assign a

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Reinhold Birkenfeld
Ron Adam wrote: > Given the statement: > > a = None > > And the following are all true: > > a == None Okay. > (a) == (None) Okay. > (a) == () Whoops! a (which is None) is equal to the empty tuple (which is not None)? > (None) == () > > Then this "conceptual" comparison should also be tr

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Mike Meyer wrote: > Ron Adam <[EMAIL PROTECTED]> writes: > >>So doing this would give an error for functions that require an argument. >> >> def foo(x): >> return x >> >> a = None >> b = foo(a)# error because a dissapears before foo gets it. > > > So how do I pass None

Re: flatten(), [was Re: map/filter/reduce/lambda opinions ...]

2005-07-06 Thread Ron Adam
Stian Søiland wrote: > Or what about a recursive generator? > > a = [1,2,[[3,4],5,6],7,8,[9],[],] > > def flatten(item): > try: > iterable = iter(item) > except TypeError: > yield item # inner/final clause > else: > for elem in

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Mike Meyer
Ron Adam <[EMAIL PROTECTED]> writes: > So doing this would give an error for functions that require an argument. > > def foo(x): > return x > > a = None > b = foo(a)# error because a dissapears before foo gets it. So how do I pass None to a function? > >>TypeErro

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Benji York wrote: > Ron Adam wrote: > >> "if extraargs:" would evaluate to "if None:", which would evaluate to >> "if:" which would give you an error. > > > In what way is "if None:" equivalent to "if:"? > -- > Benji York It's not now.. but if None where to really represent the concept None,

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread David Abrahams
functions where to disappear from Python. Note that I said "anonymous > functions", not "lambda". Concerning map, filter, reduce etc, these > functions can live in a separate module, and this wouldn't bother me. > But anonymous functions are part of the langua

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread David Abrahams
Tom Anderson <[EMAIL PROTECTED]> writes: > Comrades, > > During our current discussion of the fate of functional constructs in > python, someone brought up Guido's bull on the matter: > > http://www.artima.com/weblogs/viewpost.jsp?thread=98196 > > He says h

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Steven Bethard
Daniel Schüle wrote: > Removing lamdba would be reduce readability of Python, I think here > for examble of code like > > class App: > > > def drawLines(self, event): > from random import randint > r = lambda : randint(1, 100) > self.canvas.create_line

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Daniel Schüle
I think in some contextes map is more readable than [f() for i in S] because it's more verbatim Removing lamdba would be reduce readability of Python, I think here for examble of code like class App: def drawLines(self, event): from random i

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Benji York
Ron Adam wrote: > "if extraargs:" would evaluate to "if None:", which would evaluate to > "if:" which would give you an error. In what way is "if None:" equivalent to "if:"? -- Benji York -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Bruno Desthuilliers
Stian Søiland a écrit : > (snip) > Hey, I know! > > t = python.util.ImmutableArrayList.fromCollection(L.getAbstractCollection()) > > python.util.functional.applyFunctionOnCollection( > (class implements python.util.functional.AnonymousFunction: > def anonymousFunction(x): >

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Bruno Desthuilliers
Tom Anderson a écrit : > Comrades, > > During our current discussion of the fate of functional constructs in > python, someone brought up Guido's bull on the matter: > > http://www.artima.com/weblogs/viewpost.jsp?thread=98196 > > He says he's going to dispose

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Dan Sommers
On Wed, 6 Jul 2005 20:42:51 +0200, Stian Søiland <[EMAIL PROTECTED]> wrote: > I'm all for it. I would even be tempted of changing def to function, > but it would look stupid in: > class A: > function make_my_day(self): > return "Your day" > a = A() > since a.

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Stian Søiland wrote: > On 2005-07-06 16:33:47, Ron Adam wrote: > > >>*No more NamesError exceptions! >> print value >> >> None > > > So you could do lot's of funny things like: > > def my_fun(extra_args=None): > if not extraargs: > print "Behave normally" >

Re: flatten(), [was Re: map/filter/reduce/lambda opinions ...]

2005-07-06 Thread Stian Søiland
On 2005-07-06 00:50:30, Ron Adam wrote: > This is probably the more correct way to do it. :-) > > def flatten(seq): > i = 0 > while i!=len(seq): > while isinstance(seq[i],list): > seq[i:i+1]=seq[i] > i+=1 > return seq Or what about a recursive genera

Re: map/filter/reduce/lambda opinions and backgroundunscientificmini-survey

2005-07-06 Thread Terry Reedy
"George Sakkis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Terry Reedy" <[EMAIL PROTECTED]> wrote: > >> "George Sakkis" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >> > Still it's hard to explain why four specific python keywords - def, >> > del, exec and el

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Dan Sommers wrote: >> AttributeError: 'NoneType' object has no attribute 'read' > > > This is the one of which I was thinking. So you see this error at the > end of a (long) traceback, and try to figure out where along the (long) > line of function calls I typed the wrong name. Currently,

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-06 Thread Stian Søiland
On 2005-07-06 07:00:04, Steven D'Aprano wrote: > map(lambda x: if x == 0: 1; else: math.sin(x)/x, > myList) And now for the "readable" list comprehension version: [x==0 and 1 or math.sin(x)/x for x in myList] Now even though I'm into the short-cir

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Stian Søiland
On 2005-07-06 16:33:47, Ron Adam wrote: > *No more NamesError exceptions! > print value > >> None So you could do lot's of funny things like: def my_fun(extra_args=None): if not extraargs: print "Behave normally" extra_args = 1337 if ext

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Stian Søiland
English > dictionaries in my house, none of them have the word. Agree, I have the problem of writing "tupple" in all comments and documentations. It's a weird word indeed =) > t = immutable_list(L) > map(anonymous_function x: x+1, L) Hey, I know! t = python.util

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Stian Søiland
On 2005-07-06 02:46:27, George Sakkis wrote: > So, who would object the full-word versions for python 3K ? > def -> define > del -> delete > exec -> execute > elif -> else if I'm all for it. I would even be tempted of changing def to function, but it would look stupid in: class A: fu

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Dan Sommers
On Wed, 06 Jul 2005 15:18:31 GMT, Ron Adam <[EMAIL PROTECTED]> wrote: > Dan Sommers wrote: >> On Wed, 06 Jul 2005 14:33:47 GMT, >> Ron Adam <[EMAIL PROTECTED]> wrote: >> >>> Since this is a Python 3k item... What would be the consequence of >>> making None the default value of an undefined name?

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Dan Bishop
Devan L wrote: > > Here's a couple of examples from my own code: > > > > # from a Banzhaf Power Index calculator > > # adds things that aren't numbers > > return reduce(operator.add, > > (VoteDistributionTable({0: 1, v: 1}) for v in electoral_votes)) > > return sum([VoteDistributionTable({0:1,

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Devan L wrote: >># from a custom numeric class >># converts a tuple of digits into a number >>mantissa = sign * reduce(lambda a, b: 10 * a + b, mantissa) > > > I'll admit I can't figure out a way to replace reduce without writing > some ugly code here, but I doubt these sorts of things appear of

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Devan L
> Here's a couple of examples from my own code: > > # from a Banzhaf Power Index calculator > # adds things that aren't numbers > return reduce(operator.add, > (VoteDistributionTable({0: 1, v: 1}) for v in electoral_votes)) return sum([VoteDistributionTable({0:1, v:1} for v in electoral_votes]

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Dan Sommers wrote: > On Wed, 06 Jul 2005 14:33:47 GMT, > Ron Adam <[EMAIL PROTECTED]> wrote: > > >>Since this is a Python 3k item... What would be the consequence of >>making None the default value of an undefined name? And then assigning >>a name to None as a way to delete it? > > > [ ... ]

Deleting variables [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-06 Thread Steven D'Aprano
On Wed, 06 Jul 2005 14:28:55 +0100, Tom Anderson wrote: >> del -> delete > > How about just getting rid of del? Removal from collections could be done > with a method call, Which would be called object.del() I presume. And that opens a big can of worms. Suppose we have a list L = [4, 3, 2, 1,

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-06 Thread Steven Bethard
Ron Adam wrote: > Yes, I think a different key word would help. My current favorite > alternative is to put it in parentheses similar to list comprehensions > and use "let". > > (let x,y return x+y) If you haven't already, see: http://wiki.python.org/moin/AlternateLambdaSyntax for other simi

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Steven Bethard
Terry Hancock wrote: > And a syntax just occured to me -- what about this: > > [y*x for x,y] > > ? > > (that is: > > [ for ] If you haven't already, see: http://wiki.python.org/moin/AlternateLambdaSyntax for other similar proposals. STeVe -- http://mail.python.org/mailman/listinfo/python-l

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Dan Sommers
On Wed, 06 Jul 2005 14:33:47 GMT, Ron Adam <[EMAIL PROTECTED]> wrote: > Since this is a Python 3k item... What would be the consequence of > making None the default value of an undefined name? And then assigning > a name to None as a way to delete it? [ ... ] > Any drawbacks? Lots more hard-t

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Tom Anderson wrote: >> del -> delete > > > How about just getting rid of del? Removal from collections could be > done with a method call, and i'm not convinced that deleting variables > is something we really need to be able to do (most other languages > manage without it). Since this is a

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread François Pinard
[Tom Anderson] > > del -> delete > How about just getting rid of del? [...] i'm not convinced that > deleting variables is something we really need to be able to do While surely not in every program, I still use `del' often. Compare: x = None del x when the goal is to cut the referenc

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Tom Anderson
On Wed, 6 Jul 2005, Terry Hancock wrote: > On Tuesday 05 July 2005 03:43 pm, Tom Anderson wrote: > >> I understand that the backslash is popular in some ivory-tower >> functional languages. Currently, a backslash can be used for explicit >> line joining, and is illegal elsewhere on a line outsid

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Tom Anderson
On Wed, 5 Jul 2005, George Sakkis wrote: > "Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > >> On Tue, 05 Jul 2005 09:46:41 -0500, Terry Hancock wrote: > [snip] > >> Def would be short for ... defend? defile? defer? defame? default? deflect? >> >> There's always *something* to learn. Why def instead

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread steve . morin
map, filter, reduce and lambda Lisp constructs, bring flexibility to the language and is why I started programming in python to begin with. Removing these constructs will be a shame and one step closer to the death of some of the basic features that make python great. -- http://mail.python.org

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-06 Thread George Sakkis
"Terry Reedy" <[EMAIL PROTECTED]> wrote: > "George Sakkis" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Still it's hard to explain why four specific python keywords - def, > > del, exec and elif - were chosen to be abbreviated, > > Precedence in other languages and CS usage?

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Daniel Schüle
Full Acknowledge -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Antoon Pardon
Op 2005-07-02, Mike Meyer schreef <[EMAIL PROTECTED]>: > "Sean McIlroy" <[EMAIL PROTECTED]> writes: > >> Peter Hansen wrote: >> >>> Sean, what gave you the impression this would change? >> if that's the case then list comprehensions and/or "first class >> functions" are likely to be the next targe

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Antoon Pardon
Op 2005-07-01, Mike Meyer schreef <[EMAIL PROTECTED]>: > "iK" <[EMAIL PROTECTED]> writes: > >> Seems like he wants python programmers to solve their problems all in the >> same way. While that is great for corporate slaves it is terrible for the >> creative programmer. > > No, he wants Python to

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Steven D'Aprano
I said I'd drop the discussion about lambda, but this isn't really the same discussion even if it is part of the same thread. That's my excuse, and I'm sticking to it. Terry Hancock wrote: > On Tuesday 05 July 2005 03:43 pm, Tom Anderson wrote: > >>I understand that the backslash is popular in

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Terry Hancock
On Tuesday 05 July 2005 03:43 pm, Tom Anderson wrote: > I understand that the backslash is popular in some ivory-tower functional > languages. Currently, a backslash can be used for explicit line joining, > and is illegal elsewhere on a line outside a string literal, so i think > it's available

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Erik Max Francis
Terry Hancock wrote: > It's a generalization rather than a specialization: > > double (or couple) > triple > quadruple > quintuple > sextuple > septuple > octuple > nontuple > ... > > Maybe a wee bit less obvious, but still understandable. The general form is explicitly called an "n-tuple" or "

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Terry Hancock
On Tuesday 05 July 2005 06:57 pm, Steven D'Aprano wrote: > On Tue, 05 Jul 2005 12:11:47 -0700, mcherm wrote: > > > And besides, "def" isn't a "magic" word... it's an abreviation for > > "define"... > > Really? I thought it was an abbreviation for "definition". As in, > "definition of MyFunc is..

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Ron Adam
Robert Kern wrote: > Dan Bishop wrote: > >> There's also the issue of having to rewrite old code. > > > It's Python 3000. You will have to rewrite old code regardless if reduce > stays. > And from what I understand Python 2.x will still be maintained and supported. It will probably be more

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-05 Thread Steven D'Aprano
that lambda doesn't allow statements. They do this, not because they know about the lambda calculus (I don't!) but because they keep trying to do things like this: map(lambda x: if x == 0: 1; else: math.sin(x)/x, myList) Hands up who thinks this usage case would disappear if lamb

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-05 Thread Ron Adam
Terry Reedy wrote: > "George Sakkis" <[EMAIL PROTECTED]> wrote in message >>So, who would object the full-word versions for python 3K ? >>def -> define >>del -> delete >>exec -> execute > > > These three I might prefer to keep. > > >>elif -> else if > > > This one I dislike and would prefer

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-05 Thread Ron Adam
Terry Reedy wrote: > I also suspect that the years of fuss over Python's lambda being what it is > rather that what it is 'supposed' to be (and is in other languages) but is > not, has encourage Guido to consider just getting rid of it. I personally > might prefer keeping the feature but using

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Robert Kern
Dan Bishop wrote: > There's also the issue of having to rewrite old code. It's Python 3000. You will have to rewrite old code regardless if reduce stays. -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richar

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Dan Bishop
bda a, b: 10 * a + b, mantissa) > Also, map is easily replaced. > map(f1, sequence) == [f1(element) for element in sequence] There's also the issue of having to rewrite old code. -- http://mail.python.org/mailman/listinfo/python-list

Re: flatten(), [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-05 Thread Ron Adam
Tom Anderson wrote: > > We really ought to do this benchmark with a bigger list as input - a few > thousand elements, at least. But that would mean writing a function to > generate random nested lists, and that would mean specifying parameters > for the geometry of its nestedness, and that wou

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-05 Thread Terry Reedy
"George Sakkis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Still it's hard to explain why four specific python keywords - def, > del, exec and elif - were chosen to be abbreviated, Precedence in other languages and CS usage? > So, who would object the full-word versions for p

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-05 Thread Terry Reedy
"Steven Bethard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > OTOH, I fully agree with Peter Hansen: "Really, the name is such a > trivial, unimportant part of this whole thing that it's hardly worth > discussing." >From a certain viewpoint, I would agree. Yet, the word 'lambda

Re: flatten(), [was Re: map/filter/reduce/lambda opinions andbackground unscientific mini-survey]

2005-07-05 Thread Terry Reedy
"Tom Anderson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I guess setslice is a lot faster than i thought. Nope, the example is too short to be meaningful. > How are python lists > implemented? Presumably not as straightforward arrays, where inserting a > bunch of items at th

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread George Sakkis
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > On Tue, 05 Jul 2005 09:46:41 -0500, Terry Hancock wrote: [snip] > > Having said that, I too will miss the *concept* of an anonymous > > function, although I wouldn't mind at all if its name changed, or if it > > were somehow integrated into the "def"

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Steven Bethard
Grant Edwards wrote: > [EMAIL PROTECTED] wrote: >> So I'd say that it's a pretty obscure name that most people >> wouldn't know. > > I can't believe that anybody with any computer science > background doesn't know it. Perhaps this reflects on the quality of education in the United States ;) but

Re: flatten(), [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-05 Thread Tom Anderson
return seq flattens = [ georges_recursive_flatten, rons_nonrecursive_flatten, toms_recursive_zerocopy_flatten, toms_iterative_zerocopy_flatten, devans_smallest_recursive_flatten, rons_nonrecursive_inplace_flatten ] seq = [[1,2],[3],[],[4,[5,6]]] def timefla

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Steven D'Aprano
On Tue, 05 Jul 2005 12:11:47 -0700, mcherm wrote: > And besides, "def" isn't a "magic" word... it's an abreviation for > "define"... Really? I thought it was an abbreviation for "definition". As in, "definition of MyFunc is..." > I hope that any student who didn't understand a word as > common

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Steven D'Aprano
ng up vocabulary at an incredible rate. > > If you're arguing that language is acquired rather than innate, you are > bludgeoning an obvious point. The point is that *jargon* should ideally > derive in a natural way from commonly-used language, That's a bonus, sure. It i

Re: flatten(), [was Re: map/filter/reduce/lambda opinions ...]

2005-07-05 Thread Ron Adam
> Ok... How about a non-recursive flatten in place? ;-) > > def flatten(seq): > i = 0 > while i!=len(seq): > while isinstance(seq[i],list): > seq.__setslice__(i,i+1,seq[i]) > i+=1 > return seq > > seq = [[1,2],[3],[],[4,[5,6]]] > print flatten(seq) > > I

flatten(), [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-05 Thread Ron Adam
Tom Anderson wrote: > The trouble with these is that they make a lot of temporary lists - > George's version does it with the recursive calls to flatten, and Ron's > with the slicing and concatenating. How about a version which never > makes new lists, only appends the base list? We can use rec

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-05 Thread Ivan Van Laningham
Hi All-- Tom Anderson wrote: > > I understand that the backslash is popular in some ivory-tower functional > languages. Currently, a backslash can be used for explicit line joining, > and is illegal elsewhere on a line outside a string literal, so i think > it's available for this. It would be ut

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Tom Anderson
On Tue, 5 Jul 2005, Terry Hancock wrote: > Having said that, I too will miss the *concept* of an anonymous > function, although I wouldn't mind at all if its name changed, or if it > were somehow integrated into the "def" keyword's usage. Using backticks > or some other syntax delimiter also s

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread George Sakkis
"Devan L" wrote: > def flatten(iterable): > if not hasattr(iterable, '__iter__'): > return [iterable] > return sum([flatten(element) for element in iterable],[]) > Recursion makes things so much shorter. The last line can faster and more compact by: from itertools import imap de

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Sybren Stuvel
Grant Edwards enlightened us with: > It sounds like you ran a computer user training department. I don't > think it could be called computer science. Being a computer science student at the University of Amsterdam, I can tell you that it definitely should not be called "computer science". > I ca

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Devan L
def flatten(iterable): if not hasattr(iterable, '__iter__'): return [iterable] return sum([flatten(element) for element in iterable],[]) Recursion makes things so much shorter. -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Grant Edwards
On 2005-07-05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Up until a few years ago, I ran the computer science department at a > high-school. I provided support for the English teachers who taught > *all* students -- but they taught things like the use of a word > processor or the internet, T

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Peter Hansen
[EMAIL PROTECTED] wrote: [snip description of experience teaching high school students] > So I'd say that it's a pretty obscure name that most people wouldn't > know. It would be hard to argue against that statement; certainly "lambda" in this context (or probably any) is not a word "most people"

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread mcherm
Up until a few years ago, I ran the computer science department at a high-school. I provided support for the English teachers who taught *all* students -- but they taught things like the use of a word processor or the internet, and never covered the meaning of "lambda". I taught a computer applicat

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Christopher Subich
[EMAIL PROTECTED] wrote: > concept quickly familiar. But "lambda" has a very clear meaning... it's > a letter of the greek alphabet. The connection between that letter and > anonymous functions is tenuous at best, and fails the test of making > Python read like "executable pseudocode". But 'lambda

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Terry Hancock
On Tuesday 05 July 2005 08:17 am, Steven D'Aprano wrote: > Sorry, but you are mistaken. "lambda" is a _reserved_ word in the > Python language, while "function" etc are not, but they are certainly > part of the language. Try explaining what def and import do without > using the words "function" or

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Tom Anderson
On Mon, 4 Jul 2005, Ron Adam wrote: > George Sakkis wrote: > >> And finally for recursive flattening: >> >> def flatten(seq): >> return reduce(_accum, seq, []) >> >> def _accum(seq, x): >> if isinstance(x,list): >> seq.extend(flatten(x)) >> else: >> seq.append(x) >>

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Steven D'Aprano
On Tue, 05 Jul 2005 05:03:32 -0700, mcherm wrote: > Steven D'Aprano writes: >> Lambda is no more an obscure name than "function", "decorator", "closure", >> "class", or "module". The first time you come across it, you don't know >> what it means. Then you learn what it means, and then you know. >

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Tom Anderson
On Mon, 4 Jul 2005, George Sakkis wrote: > "Tom Anderson" <[EMAIL PROTECTED]> wrote: > >> I'll just chip in and say i'd quite like a flatten(), too; at the moment, >> i have one like this: >> >> def flatten(ll): >> return reduce(lambda a, l: a.extend(l), ll, []) > > This doesn't work; a.extend()

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread mcherm
Steven D'Aprano writes: > Lambda is no more an obscure name than "function", "decorator", "closure", > "class", or "module". The first time you come across it, you don't know > what it means. Then you learn what it means, and then you know. I believe you've made two errors here. First of all, "lam

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-04 Thread Steven Bethard
Erik Max Francis wrote: > Steven Bethard wrote: > >> And it's almost two times slower: > > That's because you're not using operator.add. Huh? Please re-read my post. That's exactly what I used. STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-04 Thread Ron Adam
George Sakkis wrote: > And finally for recursive flattening: > > def flatten(seq): > return reduce(_accum, seq, []) > > def _accum(seq, x): > if isinstance(x,list): > seq.extend(flatten(x)) > else: > seq.append(x) > return seq > > flatten(seq) > > [1, 2, 3,

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-04 Thread Carl Banks
Christopher Subich wrote: > That said, Python itself is mostly a procedural language, with the > functional tools really being bolted on[1]. [etc., snip] Yeah, that's pretty much what I said in the first place. -- CARL BANKS -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-04 Thread Erik Max Francis
Steven Bethard wrote: > And it's almost two times slower: That's because you're not using operator.add. -- Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Virtue has never been as respectable as money. -- Mar

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-04 Thread Steven Bethard
Erik Max Francis wrote: > Ron Adam wrote: > >> In this case sum and product fulfill 90% (estimate of course) of >> reduces use cases. It may actually be as high as 99% for all I know. >> Or it may be less. Anyone care to try and put a real measurement on it? > > Well, reduce covers 100% of th

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-04 Thread Christopher Subich
Carl Banks wrote: > I suspect you're misunderstanding what I mean by heavily functional. > Heavily functional programming is a different mindset altogether. In > heavily functional programming, things like maps and filters and > function applications are actually what you'r

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-04 Thread Christopher Subich
Peter Hansen wrote: > [str(parrot) for parrot in sequence], for example, tells you much more > about what is going on than str(x) does. > > Exactly what, I have no idea... but it says _so_ much more. ;-) Yarr! Avast! Etc! -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-04 Thread George Sakkis
"Tom Anderson" <[EMAIL PROTECTED]> wrote: > I'll just chip in and say i'd quite like a flatten(), too; at the moment, > i have one like this: > > def flatten(ll): > return reduce(lambda a, l: a.extend(l), ll, []) This doesn't work; a.extend() returns None, not the extended list a: >>> seq = [[

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-04 Thread Peter Hansen
Terry Hancock wrote: > On Sunday 03 July 2005 07:05 pm, Erik Max Francis wrote: >>I personally think that map looks clearer than a list comprehension for >>a simple function call > This on the other hand, >> [str(x) for x in sequence] > is practically plain Engli

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-04 Thread Tom Anderson
On Sun, 3 Jul 2005, Robert Kern wrote: > Erik Max Francis wrote: >> Ron Adam wrote: >> >>> So you are saying that anything that has a 1% use case should be included >>> as a builtin function? >>> >>> I think I can find a few hundred other functions in the library that are >>> used more than te

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-04 Thread Terry Hancock
On Sunday 03 July 2005 07:05 pm, Erik Max Francis wrote: > I personally think that map looks clearer than a list comprehension for > a simple function call, e.g. I have to disagree > map(str, sequence) This says "call a function 'map' on 'str' and &#x

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-04 Thread Carl Banks
Christopher Subich wrote: > Carl Banks wrote: > > > > Christopher Subich wrote: > >>I've heard this said a couple times now -- how can listcomps not > >>completely replace map and filter? > > If you're doing heavy functional programming, listcomps

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-04 Thread Carl Banks
Steven D'Aprano wrote: > Carl Banks wrote: > > > The shamelessness with which you inflated the verbosity of the latter > > is hilarious. > > [snip] > > > [ x**2 + y**2 for (x,y) in izip(xlist,ylist) ] > > > > Now there's no longer much a

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-03 Thread Robert Kern
thon isn't developed by votes. We tried that once before; it didn't work so well. When planning for Python 3000 really gets going, when Guido gets a year's sabbatical to work on it, when we can see how map/filter/reduce/lambda fit into the whole scheme of how this new language wor

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-03 Thread Steven D'Aprano
> functionality that covers most of the use cases for them is a good > thing. > > The latter has occured for map, filter, and reduce. Lambda I'm not so > sure of, but it gets swept up with the same broom. Moving the first > three into a library module seems like a good idea

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-03 Thread Erik Max Francis
Ron Adam wrote: > So you are saying that anything that has a 1% use case should be > included as a builtin function? > > I think I can find a few hundred other functions in the library that are > used more than ten times as often as reduce. Should those be builtins too? > > This is a practica

<    2   3   4   5   6   7   8   9   >