Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25166 > unrolled thread
| Started by | Daniel Fetchinson <fetchinson@googlemail.com> |
|---|---|
| First post | 2012-07-11 08:41 +0200 |
| Last post | 2012-07-13 13:47 -0400 |
| Articles | 20 on this page of 48 — 18 participants |
Back to article view | Back to comp.lang.python
lambda in list comprehension acting funny Daniel Fetchinson <fetchinson@googlemail.com> - 2012-07-11 08:41 +0200
Re: lambda in list comprehension acting funny "Colin J. Williams" <cjw@ncf.ca> - 2012-07-11 06:28 -0400
Re: lambda in list comprehension acting funny Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-11 10:34 -0600
Re: lambda in list comprehension acting funny 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-11 20:39 -0700
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-12 03:51 +0000
Re: lambda in list comprehension acting funny 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-11 22:04 -0700
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-12 06:18 +0000
Re: lambda in list comprehension acting funny Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-07-12 08:40 +0100
Re: lambda in list comprehension acting funny 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-11 20:39 -0700
Re: lambda in list comprehension acting funny woooee <woooee@gmail.com> - 2012-07-11 11:38 -0700
Re: lambda in list comprehension acting funny John Ladasky <john_ladasky@sbcglobal.net> - 2012-07-11 13:21 -0700
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-12 00:52 +0000
Re: lambda in list comprehension acting funny Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-11 21:05 -0400
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-12 03:53 +0000
Re: lambda in list comprehension acting funny Terry Reedy <tjreedy@udel.edu> - 2012-07-12 00:24 -0400
Re: lambda in list comprehension acting funny Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-12 00:39 -0400
Re: lambda in list comprehension acting funny Robert Miles <robertmiles@teranews.com> - 2012-08-15 19:26 -0500
Re: lambda in list comprehension acting funny John O'Hagan <research@johnohagan.com> - 2012-07-12 15:29 +1000
Re: lambda in list comprehension acting funny Robert Kern <robert.kern@gmail.com> - 2012-07-12 10:06 +0100
Re: lambda in list comprehension acting funny Hans Mulder <hansmu@xs4all.nl> - 2012-07-12 00:22 +0200
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-11 23:47 +0000
Re: lambda in list comprehension acting funny Daniel Fetchinson <fetchinson@googlemail.com> - 2012-07-12 04:54 +0200
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-12 03:59 +0000
Re: lambda in list comprehension acting funny Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-12 10:53 -0600
Re: lambda in list comprehension acting funny Rotwang <sg552@hotmail.co.uk> - 2012-07-12 18:23 +0100
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-13 02:20 +0000
Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-12 21:33 -0700
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-13 06:36 +0000
Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-13 06:44 -0700
Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-13 07:45 -0700
RE: lambda in list comprehension acting funny "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-07-13 16:12 +0000
Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-13 09:46 -0700
Re: lambda in list comprehension acting funny Chris Angelico <rosuav@gmail.com> - 2012-07-14 03:20 +1000
Re: lambda in list comprehension acting funny Hans Mulder <hansmu@xs4all.nl> - 2012-07-13 19:53 +0200
RE: lambda in list comprehension acting funny "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-07-13 18:06 +0000
Re: lambda in list comprehension acting funny Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-13 12:54 -0600
Re: lambda in list comprehension acting funny Hans Mulder <hansmu@xs4all.nl> - 2012-07-13 21:26 +0200
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-14 23:29 +0000
Re: lambda in list comprehension acting funny Chris Angelico <rosuav@gmail.com> - 2012-07-15 10:49 +1000
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-15 08:32 +0000
Re: lambda in list comprehension acting funny Chris Angelico <rosuav@gmail.com> - 2012-07-15 18:44 +1000
Re: lambda in list comprehension acting funny Hans Mulder <hansmu@xs4all.nl> - 2012-07-15 21:25 +0200
Re: lambda in list comprehension acting funny Terry Reedy <tjreedy@udel.edu> - 2012-07-15 06:27 -0400
Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-13 19:31 -0700
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-14 03:43 +0000
Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-13 21:53 -0700
Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-14 07:46 +0000
Re: lambda in list comprehension acting funny Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-13 13:47 -0400
Page 1 of 3 [1] 2 3 Next page →
| From | Daniel Fetchinson <fetchinson@googlemail.com> |
|---|---|
| Date | 2012-07-11 08:41 +0200 |
| Subject | lambda in list comprehension acting funny |
| Message-ID | <mailman.2006.1341988919.4697.python-list@python.org> |
funcs = [ lambda x: x**i for i in range( 5 ) ] print funcs[0]( 2 ) print funcs[1]( 2 ) print funcs[2]( 2 ) This gives me 16 16 16 When I was excepting 1 2 4 Does anyone know why? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown
[toc] | [next] | [standalone]
| From | "Colin J. Williams" <cjw@ncf.ca> |
|---|---|
| Date | 2012-07-11 06:28 -0400 |
| Message-ID | <jtjkng$ak6$1@theodyn.ncf.ca> |
| In reply to | #25166 |
On 11/07/2012 2:41 AM, Daniel Fetchinson wrote: > funcs = [ lambda x: x**i for i in range( 5 ) ] > print funcs[0]( 2 ) > print funcs[1]( 2 ) > print funcs[2]( 2 ) > > This gives me > > 16 > 16 > 16 > > When I was excepting > > 1 > 2 > 4 > > Does anyone know why? > > Cheers, > Daniel > > I don't understand why you would expect 1, 2, 4. Perhaps parentheses will help the order of evaluation: funcs = [(lambda x: x**i) for i in range( 5 )] This gives: 1 16 81 Colin W.
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2012-07-11 10:34 -0600 |
| Message-ID | <mailman.2014.1342024513.4697.python-list@python.org> |
| In reply to | #25172 |
On Wed, Jul 11, 2012 at 4:28 AM, Colin J. Williams <cjw@ncf.ca> wrote: > I don't understand why you would expect 1, 2, 4. Because: funcs[0](2) == 2 ** 0 == 1 funcs[1](2) == 2 ** 1 == 2 funcs[2](2) == 2 ** 2 == 4 > Perhaps parentheses will help the order of evaluation: > > funcs = [(lambda x: x**i) for i in range( 5 )] > > This gives: > 1 > 16 > 81 No, that gives 16, 16, 16 just like the original. I don't understand why you would expect 1, 16, 81, unless you have misread the code.
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2012-07-11 20:39 -0700 |
| Message-ID | <mailman.2022.1342064389.4697.python-list@python.org> |
| In reply to | #25176 |
On Thursday, July 12, 2012 12:34:33 AM UTC+8, Ian wrote:
> On Wed, Jul 11, 2012 at 4:28 AM, Colin J. Williams <cjw@ncf.ca> wrote:
> > I don't understand why you would expect 1, 2, 4.
>
> Because:
>
> funcs[0](2) == 2 ** 0 == 1
> funcs[1](2) == 2 ** 1 == 2
> funcs[2](2) == 2 ** 2 == 4
>
> > Perhaps parentheses will help the order of evaluation:
> >
> > funcs = [(lambda x: x**i) for i in range( 5 )]
> >
> > This gives:
> > 1
> > 16
> > 81
>
> No, that gives 16, 16, 16 just like the original. I don't understand
> why you would expect 1, 16, 81, unless you have misread the code.
I'll contribute my way of python programming:
def powerb(x, b): #
return x**b
One functor is enough!
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-07-12 03:51 +0000 |
| Message-ID | <4ffe49a8$0$1781$c3e8da3$76491128@news.astraweb.com> |
| In reply to | #25191 |
On Wed, 11 Jul 2012 20:39:45 -0700, 88888 Dihedral wrote: > I'll contribute my way of python programming: > > def powerb(x, b): # > return x**b Here's a shorter version: py> pow <built-in function pow> > One functor is enough! Nothing we have been discussing in this thread has been a functor, either in the Haskell sense or the C++ sense. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2012-07-11 22:04 -0700 |
| Message-ID | <6b5861df-aa4c-42bc-b013-e0bf2b94ca7e@googlegroups.com> |
| In reply to | #25192 |
On Thursday, July 12, 2012 11:51:04 AM UTC+8, Steven D'Aprano wrote: > On Wed, 11 Jul 2012 20:39:45 -0700, 88888 Dihedral wrote: > > > I'll contribute my way of python programming: > > > > def powerb(x, b): # > > return x**b > > Here's a shorter version: > > py> pow > <built-in function pow> > > > > One functor is enough! > > Nothing we have been discussing in this thread has been a functor, either > in the Haskell sense or the C++ sense. > > > > -- > Steven Well, I encountered this kind of problems before in OOP. I have to make sure my functor to keep the state variable values for different objects that call the same functor to behave correctly in order to avoid passing extra parameters in various objects using the same functor.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-07-12 06:18 +0000 |
| Message-ID | <4ffe6c42$0$1781$c3e8da3$76491128@news.astraweb.com> |
| In reply to | #25198 |
On Wed, 11 Jul 2012 22:04:51 -0700, 88888 Dihedral wrote: > I have to make sure my functor to keep the state variable values for > different objects that call the same functor to behave correctly in > order to avoid passing extra parameters in various objects using the > same functor. Yo dawg, I heard you liked functors, so I put a functor in your functor so you can train your markov chains with extra functor parameters to functor objects that are functor factory decorator functors. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2012-07-12 08:40 +0100 |
| Message-ID | <mailman.2029.1342078750.4697.python-list@python.org> |
| In reply to | #25201 |
On 12/07/2012 07:18, Steven D'Aprano wrote: > On Wed, 11 Jul 2012 22:04:51 -0700, 88888 Dihedral wrote: > >> I have to make sure my functor to keep the state variable values for >> different objects that call the same functor to behave correctly in >> order to avoid passing extra parameters in various objects using the >> same functor. > > Yo dawg, I heard you liked functors, so I put a functor in your functor > so you can train your markov chains with extra functor parameters to > functor objects that are functor factory decorator functors. > > > functory :) Ooh, that's bad even by my standards. -- Cheers. Mark Lawrence.
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2012-07-11 20:39 -0700 |
| Message-ID | <62b4a584-42ca-4e10-af12-18b6f66eed76@googlegroups.com> |
| In reply to | #25176 |
On Thursday, July 12, 2012 12:34:33 AM UTC+8, Ian wrote:
> On Wed, Jul 11, 2012 at 4:28 AM, Colin J. Williams <cjw@ncf.ca> wrote:
> > I don't understand why you would expect 1, 2, 4.
>
> Because:
>
> funcs[0](2) == 2 ** 0 == 1
> funcs[1](2) == 2 ** 1 == 2
> funcs[2](2) == 2 ** 2 == 4
>
> > Perhaps parentheses will help the order of evaluation:
> >
> > funcs = [(lambda x: x**i) for i in range( 5 )]
> >
> > This gives:
> > 1
> > 16
> > 81
>
> No, that gives 16, 16, 16 just like the original. I don't understand
> why you would expect 1, 16, 81, unless you have misread the code.
I'll contribute my way of python programming:
def powerb(x, b): #
return x**b
One functor is enough!
[toc] | [prev] | [next] | [standalone]
| From | woooee <woooee@gmail.com> |
|---|---|
| Date | 2012-07-11 11:38 -0700 |
| Message-ID | <d390ef92-5316-422b-b180-5a944d33fd68@d6g2000pbt.googlegroups.com> |
| In reply to | #25166 |
You should not be using lambda in this case .for x in [2, 3]: . funcs = [x**ctr for ctr in range( 5 )] . for p in range(5): . print x, funcs[p] . print
[toc] | [prev] | [next] | [standalone]
| From | John Ladasky <john_ladasky@sbcglobal.net> |
|---|---|
| Date | 2012-07-11 13:21 -0700 |
| Message-ID | <c023034b-d23e-4392-b845-232f1ec35f05@googlegroups.com> |
| In reply to | #25178 |
Exactly. It's threads like these which remind me why I never use lambda. I would rather give a function an explicit name and adhere to the familiar Python syntax, despite the two extra lines of code. I don't even like the name "lambda". It doesn't tell you what it is (unless you're John McCarthy), a function that you won't re-use and so you don't really need to give it a persistent name. I haven't seen any lambdas in any Python library code, or in any of the third-party modules I use (numpy, matplotlib, Biopython). Do they exist? Because I have not been forced to do so, I haven't retained a space in the top drawer of my programming brain for lambda. I know the historical reason that Python ended up with lambda, it was requested by people in the Lisp community. While I appreciate some of the Lisp-like features which did find their way into Python (especially being able to treat code as data, and functions as objects), I've found that lambda does nothing for me.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-07-12 00:52 +0000 |
| Message-ID | <4ffe1fb8$0$29965$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #25179 |
On Wed, 11 Jul 2012 13:21:34 -0700, John Ladasky wrote:
> Exactly. It's threads like these which remind me why I never use
> lambda. I would rather give a function an explicit name and adhere to
> the familiar Python syntax, despite the two extra lines of code.
lambda is familiar Python syntax, or at least it should be if you
consider yourself an expert Python programmer.
And besides, this is not a problem with lambda. You get the *exact* same
problem with "ordinary" function definitions. Of course you do -- lambdas
*are* ordinary functions, they just have a more compact syntax.
funcs = []
for i in range(5):
def pwr(x):
return x**i
print("Testing 3**%d:" % i, pwr(3))
funcs.append(pwr)
for j in range(5):
print("Expected", 3**j, "got", funcs[j](3))
gives you *exactly* the same issue as with the lambda. This is not a
problem with lambdas, this is a scoping issue.
> I don't even like the name "lambda". It doesn't tell you what it is
Whereas "def" does?
If you can learn that "def" defines a function (as opposed to a class, a
module, or anything else really) than it's not that hard to learn that
"lambda" also defines a function.
Although I do wonder whether people would be less scared of lambda, and
less likely to imagine that it creates something with strange mysterious
properties different from "regular functions", if the keyword was called
"function" instead of lambda?
> (unless you're John McCarthy), a function that you won't re-use and so
> you don't really need to give it a persistent name.
Whether or not a function has a persistent name has nothing to do with
reuse. Anonymous functions can be reused. The driving motivation for
lambdas is for callback functions, which are frequently reused, but you
don't need or want to fill your global namespace up with potentially
hundreds of callback functions.
Lambda syntax is only incidentally good for saving a line or two. If the
only benefit of lambda was to save a line of code, that would be stupid.
The real reason for lambda is to avoid polluting your namespace with
unnecessary names.
Python allows us to easily and simply use anonymous strings, anonymous
ints, anonymous objects of all types. Why should functions be treated as
second-class?
> I haven't seen any lambdas in any Python library code, or in any of the
> third-party modules I use (numpy, matplotlib, Biopython). Do they
> exist? Because I have not been forced to do so, I haven't retained a
> space in the top drawer of my programming brain for lambda.
There are over 800 uses of lambda in the standard library:
[steve@ando ~]$ cd /usr/local/lib/python3.2
[steve@ando python3.2]$ grep lambda *.py */*.py | wc -l
829
(although some of the above are comments, doctests, etc.)
See, for example, configparser, decimal, functools, gettext, inspect,
pydoc, symtable, uuid, and others. pydoc and idlelib in particular make
heavy use of lambda, and the test suite is overflowing with them -- over
600 uses in total.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-07-11 21:05 -0400 |
| Message-ID | <mailman.2019.1342055140.4697.python-list@python.org> |
| In reply to | #25179 |
On Wed, 11 Jul 2012 13:21:34 -0700 (PDT), John Ladasky
<john_ladasky@sbcglobal.net> declaimed the following in
gmane.comp.python.general:
> I know the historical reason that Python ended up with lambda, it was requested by people in the Lisp community. While I appreciate some of the Lisp-like features which did find their way into Python (especially being able to treat code as data, and functions as objects), I've found that lambda does nothing for me.
It can be useful when defining callbacks for GUIs that need a
predefined argument... eg; a calculator application: 10 buttons for 0-9.
Why define 10 separate callbacks when you only need one callback with a
parameter containing the numeric value for the button.
lambda x=#: number_button_callback(x)
where # is the (integral) value of the specific button.
{non sequitur: I still recall my archaic C++ class with the OOAD
assignment of designing said calculator -- we never had to implement
one, just design the basic classes/methods/attributes [on 3x5 cards] for
a four-banger. I managed to persuade the team I was on that an RPN
calculator would be simpler to (potentially) implement... And THEN
persuaded them to NOT use the equivalent of an ALU class, but to put the
math work into each operation button... Justification when presented to
class: one could turn that four-banger into a scientific [or financial]
calculator by just adding classes for the additional function buttons
[and of course, buttons on screen] rather than having to rewrite an
"ALU" class to understand all functions.}
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-07-12 03:53 +0000 |
| Message-ID | <4ffe4a1f$0$1781$c3e8da3$76491128@news.astraweb.com> |
| In reply to | #25186 |
On Wed, 11 Jul 2012 21:05:30 -0400, Dennis Lee Bieber wrote:
> {non sequitur: I still recall my archaic C++ class with the OOAD
> assignment of designing said calculator -- we never had to implement
> one, just design the basic classes/methods/attributes [on 3x5 cards] for
> a four-banger. I managed to persuade the team I was on that an RPN
> calculator would be simpler to (potentially) implement... And THEN
> persuaded them to NOT use the equivalent of an ALU class, but to put the
> math work into each operation button...
"ALU class"?
Googling gives me no clue.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2012-07-12 00:24 -0400 |
| Message-ID | <mailman.2023.1342067108.4697.python-list@python.org> |
| In reply to | #25193 |
On 7/11/2012 11:53 PM, Steven D'Aprano wrote:
> On Wed, 11 Jul 2012 21:05:30 -0400, Dennis Lee Bieber wrote:
>
>> {non sequitur: I still recall my archaic C++ class with the OOAD
>> assignment of designing said calculator -- we never had to implement
>> one, just design the basic classes/methods/attributes [on 3x5 cards] for
>> a four-banger. I managed to persuade the team I was on that an RPN
>> calculator would be simpler to (potentially) implement... And THEN
>> persuaded them to NOT use the equivalent of an ALU class, but to put the
>> math work into each operation button...
>
> "ALU class"?
>
> Googling gives me no clue.
4th hit: Arithmetic Logic Unit (hardware) -- Wikipedia
ALU class -- software version or simulation thereof.
The hardware version of Dennis's distributed design would be
interesting. Spreadsheets are based in part on the same idea of
distributed logic and arithmetic.
--
Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-07-12 00:39 -0400 |
| Message-ID | <mailman.2024.1342067998.4697.python-list@python.org> |
| In reply to | #25193 |
On 12 Jul 2012 03:53:03 GMT, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> declaimed the following in
gmane.comp.python.general:
> "ALU class"?
>
> Googling gives me no clue.
Arithmetic/Logic Unit
http://en.wikipedia.org/wiki/Arithmetic_logic_unit
http://en.wikipedia.org/wiki/74181
{diversion: http://en.wikipedia.org/wiki/VAX-11/780 -- incredible...
that used to be considered a "super-mini" when I worked on them; and now
would be shamed by most laptops except for the ability to support so
many users concurrently (let me know when a Windows laptop supports 32
VT-100 class connections <G>)}
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Robert Miles <robertmiles@teranews.com> |
|---|---|
| Date | 2012-08-15 19:26 -0500 |
| Message-ID | <Z6XWr.31950$Bw1.15548@newsfe05.iad> |
| In reply to | #25197 |
On 7/11/2012 11:39 PM, Dennis Lee Bieber wrote:
> On 12 Jul 2012 03:53:03 GMT, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> declaimed the following in
> gmane.comp.python.general:
>
>
>> "ALU class"?
>>
>> Googling gives me no clue.
>
> Arithmetic/Logic Unit
>
> http://en.wikipedia.org/wiki/Arithmetic_logic_unit
> http://en.wikipedia.org/wiki/74181
> {diversion: http://en.wikipedia.org/wiki/VAX-11/780 -- incredible...
> that used to be considered a "super-mini" when I worked on them; and now
> would be shamed by most laptops except for the ability to support so
> many users concurrently (let me know when a Windows laptop supports 32
> VT-100 class connections <G>)}
Installing Cygwin (a Linux emulation) under Windows appears to add some
VT-100 support but without an easy way to find documentation on whether
it can support 32 of them or not.
I used to work on a VAX 11/780 and also a VAX 8600.
Cygwin has a version of Python available, in case you're interested.
Robert Miles
[toc] | [prev] | [next] | [standalone]
| From | John O'Hagan <research@johnohagan.com> |
|---|---|
| Date | 2012-07-12 15:29 +1000 |
| Message-ID | <mailman.2025.1342070992.4697.python-list@python.org> |
| In reply to | #25179 |
On Wed, 11 Jul 2012 13:21:34 -0700 (PDT) John Ladasky <john_ladasky@sbcglobal.net> wrote: > Exactly. It's threads like these which remind me why I never use lambda. I > would rather give a function an explicit name and adhere to the familiar > Python syntax, despite the two extra lines of code. I don't even like the > name "lambda". It doesn't tell you what it is (unless you're John McCarthy), > a function that you won't re-use and so you don't really need to give it a > persistent name. > > I haven't seen any lambdas in any Python library code, or in any of the > third-party modules I use (numpy, matplotlib, Biopython). Do they exist? > Because I have not been forced to do so, I haven't retained a space in the > top drawer of my programming brain for lambda. [...] +1 about the name, -1 about the usefulness. For example it's a clear and concise way to pass a key argument to min, max, sort and friends: sort(seq, key=lambda x: x.a) The alternative is to have trivial function definitions floating around the namespace which readers of the code have to search for. -- John
[toc] | [prev] | [next] | [standalone]
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Date | 2012-07-12 10:06 +0100 |
| Message-ID | <mailman.2030.1342084030.4697.python-list@python.org> |
| In reply to | #25179 |
On 7/11/12 9:21 PM, John Ladasky wrote: > Exactly. It's threads like these which remind me why I never use lambda. I would rather give a function an explicit name and adhere to the familiar Python syntax, despite the two extra lines of code. I don't even like the name "lambda". It doesn't tell you what it is (unless you're John McCarthy), a function that you won't re-use and so you don't really need to give it a persistent name. > > I haven't seen any lambdas in any Python library code, or in any of the third-party modules I use (numpy, matplotlib, Biopython). Do they exist? Because I have not been forced to do so, I haven't retained a space in the top drawer of my programming brain for lambda. I count 162 uses in the Python standard library, 69 uses in numpy, 108 in matplotlib, and 238 uses in Biopython. Adding in the unit tests for each would add significantly to those counts. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
[toc] | [prev] | [next] | [standalone]
| From | Hans Mulder <hansmu@xs4all.nl> |
|---|---|
| Date | 2012-07-12 00:22 +0200 |
| Message-ID | <4ffdfc8f$0$6921$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #25178 |
On 11/07/12 20:38:18, woooee wrote:
> You should not be using lambda in this case
> .for x in [2, 3]:
> . funcs = [x**ctr for ctr in range( 5 )]
> . for p in range(5):
> . print x, funcs[p]
> . print
The list is called "funcs" because it is meant to contain functions.
Your code does not put functions in the list, so it doesn't do what
he wants.
He could do:
funcs = []
for i in range(5):
def f(x):
return x**i
funcs.append(f)
print funcs[0]( 2 )
print funcs[1]( 2 )
print funcs[2]( 2 )
.... and it will print 16, 16, 16 for the same reason as the lambda
version. On the other hand, this does what he wants:
funcs = []
for i in range(5):
def f(x, i=i):
return x**i
funcs.append(f)
print funcs[0]( 2 )
print funcs[1]( 2 )
print funcs[2]( 2 )
The lambda keyword is a red herring. The question is really about
functions, and how they handle non-local variables. The good news
is that 'lambda' and 'def' work exactly the same in that regards.
So once you understand the finer points about 'def', you no longer
have a reason to avoid 'lambda'.
Hope this helps,
-- HansM
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.python
csiph-web