Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Thomas Passin
On 3/10/2023 11:15 PM, aapost wrote: On 3/10/23 22:16, Thomas Passin wrote: [...] The additional note in the above is, when taking the def route above, the thing you would have to consider is what scope is the dictionary pids? Do you need to submit it to the lambda and subsequently the

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread aapost
"] else None, pids.update({"user" :subprocess.Popen(["cmd4"])}) if not pids["user"] else None, I'd make the pattern in this example even more understandable and less error-prone: def update_pids(target):     cmd = ["tail", "-n", &quo

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Thomas Passin
sy-to-read and easy-to-understand expression to use in the lambda. I don't care about the exact details here. The command wasn't even mine. But you only have to scan it and grasp it once, in the def:, and then only until you get it working. In the lambda, my suggestions makes it m

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread 2QdxY4RzWzUUiLuE
On 2023-03-10 at 22:16:05 -0500, Thomas Passin wrote: > I'd make the pattern in this example even more understandable and less > error-prone: > > def update_pids(target): > cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] > pids.update({target: subprocess.Popen(cmd)}) if not \ >

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Thomas Passin
t;user" :subprocess.Popen(["cmd4"])}) if not pids["user"] else None, I'd make the pattern in this example even more understandable and less error-prone: def update_pids(target): cmd = ["tail", "-n", "1", "-f", f&quo

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread aapost
On 3/9/23 15:25, Thomas Passin wrote: >>> # this is a code snippet from a Tkinter gui app >>> # in this case lambda is quite convenient >>> self.btn_cancel = Button(self.progress_container, text='Cancel', >>> command=lambda: subprocess.call

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread aapost
"/var/log/user.log"])}) if not main.pids["user"] else None, which does start to break down readability due to line length, as there isn't really an indention rule set for something uncommonly used. but some renaming makes the pattern clearer pids.update({"messa

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Cameron Simpson
On 09Mar2023 17:55, aapost wrote: On 3/9/23 16:37, Cameron Simpson wrote: Just a note that some code formatters use a trailing comma on the last element to make the commas fold points. Both yapf (my preference) and black let you write a line like (and, indeed, flatten if short enough):    

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread aapost
On 3/9/23 16:37, Cameron Simpson wrote: On 09Mar2023 09:06, Alan Gauld wrote: Just a note that some code formatters use a trailing comma on the last element to make the commas fold points. Both yapf (my preference) and black let you write a line like (and, indeed, flatten if short enough):

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread aapost
esn't work in a lambda). It comes from a use case I needed to solve in the shortcoming of tk with frames not being scrollable, requiring a canvas. When dynamically generating a series of widgets (i.e. loading a custom json/xml layout config file), getting the scrollable area right is a

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Chris Angelico
On Fri, 10 Mar 2023 at 07:43, Thomas Passin wrote: > > On 3/9/2023 3:29 AM, aapost wrote: > > The 'what I am trying to do' is ask a question regarding opinions and > > practices on issuing a sequence of actions within a lambda via a tuple > > (since the com

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Cameron Simpson
On 09Mar2023 09:06, Alan Gauld wrote: Also layout is all important here. It could get very messy to read if indentation isn't clear. You only have to look at some Javascript code with function definitions as arguments to functions to see how clunky that can be. Just a note that some code forma

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Cameron Simpson
On 09Mar2023 09:06, Alan Gauld wrote: On 08/03/2023 21:56, aapost wrote: When making a UI there are a lot of binding/trace operations that need to occur that lead to a lot of annoying 1 use function definitions. I don't really see lambda use like below. Lambdas are very common i

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Thomas Passin
On 3/9/2023 3:29 AM, aapost wrote: The 'what I am trying to do' is ask a question regarding opinions and practices on issuing a sequence of actions within a lambda via a tuple (since the common practice approaches against it - mainly with tkinter - feel more convoluted), and i

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread aapost
On 3/9/23 00:13, Thomas Passin wrote: lol.. 'us'.. So.. to give an example from your own code: but_play = Tk.Button(_frame, text='Play', width = BUTTONWIDTH + 1, pady = PADY, command=lambda x=plotmgr:play_macro(x), bg = BUTTON_BG, font = NEWFONT) Can be written as:

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Weatherby,Gerard
Other than the admittedly subjective viewpoint that using the lambda is confusing, there’s probably nothing wrong with the lambda approach. A couple of alternatives: def e(): for e in (e1,e2,e3): e.config(state="normal") b = tk.Button(master=main, text="Enable&quo

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Alan Gauld
On 08/03/2023 21:56, aapost wrote: > When making a UI there are a lot of binding/trace operations that need > to occur that lead to a lot of annoying 1 use function definitions. I > don't really see lambda use like below. Lambdas are very common in GUI callbacks but I admit I

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread Thomas Passin
you actually said clearly what you want to achieve. So as far as the examples given above (which I can't really parse), if you meant for passing in a bool value, to do so would require something like: b.config(command=lambda enabled: config_b_and_entries(enabled)) As best as I can underst

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread aapost
reference to a callable configured, set with the command= parameter in .config() The code: def func(): pass b.config(command=func) Is equivalent. So that if the button is clicked, code at func (or the lambda) gets called. In both cases (as per my intent), care about the return values o

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread Cameron Simpson
On 08Mar2023 16:56, aapost wrote: When making a UI there are a lot of binding/trace operations that need to occur that lead to a lot of annoying 1 use function definitions. I don't really see lambda use like below. Giving 2 working lambda examples using a returned tuple to accom

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread Thomas Passin
On 3/8/2023 4:56 PM, aapost wrote: b = tk.Button(master=main, text="Enable") b.config(     command=lambda: (     e1.config(state="normal"),     e2.config(state="normal"),     e3.config(state="normal")     ) ) It's hard to unders

Lambda returning tuple question, multi-expression

2023-03-08 Thread aapost
When making a UI there are a lot of binding/trace operations that need to occur that lead to a lot of annoying 1 use function definitions. I don't really see lambda use like below. Giving 2 working lambda examples using a returned tuple to accomplish multiple expressions - what so

Re: Tuple unpacking inside lambda expressions

2022-04-21 Thread Peter Otten
On 20/04/2022 13:01, Sam Ezeh wrote: I went back to the code recently and I remembered what the problem was. I was using multiprocessing.Pool.pmap which takes a callable (the lambda here) so I wasn't able to use comprehensions or starmap Is there anything for situations like these?

Re: Tuple unpacking inside lambda expressions

2022-04-20 Thread Albert-Jan Roskam
On Apr 20, 2022 13:01, Sam Ezeh wrote: I went back to the code recently and I remembered what the problem was. I was using multiprocessing.Pool.pmap which takes a callable (the lambda here) so I wasn't able to use comprehensions or starmap Is there anythin

RE: lambda issues

2022-04-20 Thread Schachner, Joseph
Re: "...which takes a callable (the lambda here)" Python lamdas have some severe restrictions. In any place that takes a callable, if a lambda can't serve, just use def to write a function and use the function name. Joseph S. Teledyne Confidential; Commercially Sensitiv

Re: Tuple unpacking inside lambda expressions

2022-04-20 Thread Sam Ezeh
I went back to the code recently and I remembered what the problem was. I was using multiprocessing.Pool.pmap which takes a callable (the lambda here) so I wasn't able to use comprehensions or starmap Is there anything for situations like these? Kind Regards, Sam Ezeh On Sat, 16 Apr 2022

Re: Tuple unpacking inside lambda expressions

2022-04-20 Thread Sam Ezeh
) relating to unpacking inside lambda expressions? > > > > I found myself wanting to write the following. > > > > ``` > > map( > > lambda (module, data): result.process(module, data), > > jobs > > ) > > ``` > > However, it's o

Re: Tuple unpacking inside lambda expressions

2022-04-19 Thread Antoon Pardon
Op 16/04/2022 om 23:36 schreef Sam Ezeh: Two questions here. Firstly, does anybody know of existing discussions (e.g. on here or on python-ideas) relating to unpacking inside lambda expressions? I found myself wanting to write the following. ``` map( lambda (module, data): result.process

Re: Tuple unpacking inside lambda expressions

2022-04-16 Thread Sam Ezeh
> In general, if you're using map() with a lambda function, it's often simpler to switch to a comprehension. Oh, of course, completely went past my head. > [result.process(module, data) for module, data in jobs] And this works great, thanks! On Sat, 16 Apr 2022 at 22:42, Chris

Re: Tuple unpacking inside lambda expressions

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 07:37, Sam Ezeh wrote: > > Two questions here. > > Firstly, does anybody know of existing discussions (e.g. on here or on > python-ideas) relating to unpacking inside lambda expressions? > > I found myself wanting to write the following. > > ```

Tuple unpacking inside lambda expressions

2022-04-16 Thread Sam Ezeh
Two questions here. Firstly, does anybody know of existing discussions (e.g. on here or on python-ideas) relating to unpacking inside lambda expressions? I found myself wanting to write the following. ``` map( lambda (module, data): result.process(module, data), jobs ) ``` However

Re: Confusing error message: lambda walruses

2021-10-06 Thread Thomas Jollans
On 06/10/2021 23:53, Chris Angelico wrote: On Thu, Oct 7, 2021 at 8:51 AM Thomas Jollans wrote: On 03/10/2021 01:39, Chris Angelico wrote: Using assignment expressions in lambda functions sometimes works, but sometimes doesn't. Does this commit by a certain Chris Angelico help clear t

Re: Confusing error message: lambda walruses

2021-10-06 Thread Chris Angelico
On Thu, Oct 7, 2021 at 8:51 AM Thomas Jollans wrote: > > On 03/10/2021 01:39, Chris Angelico wrote: > > Using assignment expressions in lambda functions sometimes works, but > > sometimes doesn't. > > Does this commit by a certain Chris Angelico help clear things up?

Re: Confusing error message: lambda walruses

2021-10-06 Thread Thomas Jollans
On 03/10/2021 01:39, Chris Angelico wrote: Using assignment expressions in lambda functions sometimes works, but sometimes doesn't. Does this commit by a certain Chris Angelico help clear things up? https://github.com/python/peps/commit/f906b988b20c9a8e7e13a2262f5381bd2b1399e2 --

Re: Confusing error message: lambda walruses

2021-10-03 Thread Peter J. Holzer
On 2021-10-03 10:39:38 +1100, Chris Angelico wrote: > # Oh, and it doesn't actually assign anything. > >>> def f(n): > ... return (lambda: (n := 1)), (lambda: n) > ... > >>> g, h = f(5) > >>> h() > 5 > >>> g() > 1 > >&

Re: Confusing error message: lambda walruses

2021-10-03 Thread Peter J. Holzer
On 2021-10-03 10:39:38 +1100, Chris Angelico wrote: > Using assignment expressions in lambda functions sometimes works, but > sometimes doesn't. > ... return lambda x: (x, x := 2, x) syntax ok > return lambda: n := 1 syntax error > ... return lambda: (n := 1) syn

Confusing error message: lambda walruses

2021-10-02 Thread Chris Angelico
Using assignment expressions in lambda functions sometimes works, but sometimes doesn't. Python 3.11.0a0 (heads/main:dc878240dc, Oct 3 2021, 10:28:40) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. # Fi

Re: Pandas: How does df.apply(lambda work to create a result

2021-05-27 Thread Cameron Simpson
ly repr(t) if you were at the interactive prompt. It is a human readable printout of "t". >t.apply(lambda x: [x]) gives >a[[1, 2, 2]] >b[[1, 2, 2]] >How?? When you 't' within console the entire data frame is dumped but how are >the individual elements pa

Pandas: How does df.apply(lambda work to create a result

2021-05-26 Thread Veek M
t = pd.DataFrame([[4,9],]*3, columns=['a', 'b']) a b 0 4 9 1 4 9 2 4 9 t.apply(lambda x: [x]) gives a[[1, 2, 2]] b[[1, 2, 2]] How?? When you 't' within console the entire data frame is dumped but how are the individual elements passed into .apply(

Re: Lambda in parameters

2020-12-19 Thread Abdur-Rahmaan Janhangeer
Greetings list, Jane Street is well known for its love of functional programming in general and of OCaml in particular. If you don't know OCaml yet, I highly recommend it. You can think of it as Python with (static) types. Yes i know OCaml when i was exploring haskell and the like. At that tim

Re: Lambda in parameters

2020-12-19 Thread Abdur-Rahmaan Janhangeer
Greetings list, Why car and cdr? Well obviously car is content of the address register and cdr is content of data register. Apparently an artefact of a early implementation of lisp. Oh did not know that detail. More twists for sure. Thought lisp did not go lowlevel. Kind Regards, Abdur-Rahma

Re: Lambda in parameters

2020-12-19 Thread Abdur-Rahmaan Janhangeer
Greetings, Very clear explanations, rewriting lambdas as a function was the key to understand it. Did not know was a lisp inspiration. My mind still spiralling XD Kind Regards, Abdur-Rahmaan Janhangeer about | blog github

Re: Lambda in parameters

2020-12-19 Thread Greg Ewing
On 18/12/20 7:02 pm, Cameron Simpson wrote: Frankly, I think this is a terrible way to solve this problem, whatever the problem was supposed to be - that is not clear. It demonstrates that a programming language doesn't strictly need data structes -- you can do everything with nothing but funct

Re: Lambda in parameters

2020-12-19 Thread Cameron Simpson
On 19Dec2020 07:39, Philippe Meunier wrote: >See also the example reduction >here: https://en.wikipedia.org/wiki/Church_encoding#Church_pairs Thank you for this reference. I've stuck it on my reading list. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Lambda in parameters

2020-12-19 Thread Philippe Meunier
Abdur-Rahmaan Janhangeer wrote: >The aim of car is to return 1 >but i don't understand how lambda achieves this Cameron Simpson's explanation is very good. See also the example reduction here: https://en.wikipedia.org/wiki/Church_encoding#Church_pairs >This problem was a

Re: Lambda in parameters

2020-12-18 Thread Grant Edwards
On 2020-12-18, Barry wrote: >> Implement car and cdr. > Why car and cdr? > > Well obviously car is content of the address register and cdr is content of > data register. > Apparently an artefact of a early implementation of lisp. While car and cdr are lisp operators, the "content of address reg

Re: Lambda in parameters

2020-12-18 Thread Julio Di Egidio
On Friday, 18 December 2020 at 15:20:59 UTC+1, Abdur-Rahmaan Janhangeer wrote: > The Question: > > # --- > This problem was asked by Jane Street. > > cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first > and last element of that pair. For example, car(cons(3, 4)) retur

Re: Lambda in parameters

2020-12-18 Thread Barry
s "a, b" and returns the result. For ultra >> trickiness, those 2 values "a, b" are the ones you passed to the initial >> call to cons(). >> >> This last bit is a closure: when you define a function, any nonlocal >> variables (those you use but nev

Re: Lambda in parameters

2020-12-18 Thread Abdur-Rahmaan Janhangeer
losure: when you define a function, any nonlocal > variables (those you use but never assign to) have the defining scope > available for finding them. So the "pair" function gets "a" and "b" from > those you passed to "cons". > > Anyway, cons(

Re: Lambda in parameters

2020-12-17 Thread Cameron Simpson
) have the defining scope available for finding them. So the "pair" function gets "a" and "b" from those you passed to "cons". Anyway, cons() returns a "pair" function hooked to the "a" and "b" you called it with. >def car(c)

Lambda in parameters

2020-12-17 Thread Abdur-Rahmaan Janhangeer
Greetings list, Here is a famous question's solution def cons(a, b): def pair(f): return f(a, b) return pair def car(c): return c(lambda a, b: a) print(cons(1, 2)(lambda a, b: a)) print(car(cons(1, 2))) The aim of car is to return 1 but i don't understand

Re: Error in lambda function..!

2020-08-29 Thread Rob Cliffe via Python-list
On 29/08/2020 08:58, Shivlal Sharma wrote: from functools import* nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] add = reduce(lambda a : a + 1, nums) print(add) error: - TypeError Traceback (most recent call last) in () 1 from functools import* 2 nums = [1

Re: Error in lambda function..!

2020-08-29 Thread Peter Otten
Shivlal Sharma wrote: > from functools import* > nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > add = reduce(lambda a : a + 1, nums) > print(add) > > error: - > TypeError Traceback (most recent call > last) in () > 1 from functools import

Error in lambda function..!

2020-08-29 Thread Shivlal Sharma
from functools import* nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] add = reduce(lambda a : a + 1, nums) print(add) error: - TypeError Traceback (most recent call last) in () 1 from functools import* 2 nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > 3 add = red

Re: Strange use of Lambda arrow

2020-06-06 Thread edmondo . giovannozzi
lution > architect so he is very skilled (much more than me!). I am now analysing > his code to finish the job but i don't get this use of the lambda arrow, > it's like he is deplaring the returned tipe in the function signature (as > you would do in Java). I have never seen s

Re: Strange use of Lambda arrow

2020-06-05 Thread Cameron Simpson
On 06Jun2020 02:48, MRAB wrote: On 2020-06-06 01:01, Chris Angelico wrote: On Sat, Jun 6, 2020 at 8:24 AM Cameron Simpson wrote: The OP may be being confused by JavaScript, where they have "arrow functions", which are what Python calls lambda: anonymous functions. It uses an ar

Re: Strange use of Lambda arrow

2020-06-05 Thread MRAB
On 2020-06-06 01:01, Chris Angelico wrote: On Sat, Jun 6, 2020 at 8:24 AM Cameron Simpson wrote: The OP may be being confused by JavaScript, where they have "arrow functions", which are what Python calls lambda: anonymous functions. It uses an arrow in the syntax: (x,y) ->

Re: Strange use of Lambda arrow

2020-06-05 Thread Chris Angelico
On Sat, Jun 6, 2020 at 8:24 AM Cameron Simpson wrote: > The OP may be being confused by JavaScript, where they have "arrow > functions", which are what Python calls lambda: anonymous functions. It > uses an arrow in the syntax: > > (x,y) -> x+y > In JS, they

Re: Strange use of Lambda arrow

2020-06-05 Thread Cameron Simpson
than me!). I am now analysing his code to finish the job but i don't get this use of the lambda arrow, it's like he is deplaring the returned tipe in the function signature (as you would do in Java). I have never seen something like this in python.. Can someone please explain to me this

Re: Strange use of Lambda arrow

2020-06-05 Thread Chris Angelico
g > his code to finish the job but i don't get this use of the lambda arrow, > it's like he is deplaring the returned tipe in the function signature (as > you would do in Java). I have never seen something like this in python.. > > Can someone please explain to me this usage

Strange use of Lambda arrow

2020-06-05 Thread Agnese Camellini
Hello to everyone, lately i building up an open source project, with some collaborator, but one of them cannot contribute any more. He is a solution architect so he is very skilled (much more than me!). I am now analysing his code to finish the job but i don't get this use of the lambda

Re: Why lambda in loop requires default?

2016-03-28 Thread Antoon Pardon
Op 27-03-16 om 03:46 schreef gvim: > Given that Python, like Ruby, is an object-oriented language why doesn't this: It has nothing to do with being object-oriented but by how scopes are used > def m(): > a = [] > for i in range(3): a.append(lambda: i) > return a Pyt

Re: Why lambda in loop requires default?

2016-03-27 Thread Terry Reedy
On 3/26/2016 9:46 PM, gvim wrote: Given that Python, like Ruby, is an object-oriented language why doesn't this: def m(): a = [] for i in range(3): a.append(lambda: i) return a def echo_i: return i b = m() for n in range(3): print(b[n]()) # => 2 2 2 ) # =&g

Re: Why lambda in loop requires default?

2016-03-27 Thread Ned Batchelder
t behavior is concerned. > why doesn't > this: > > def m(): >a = [] > for i in range(3): a.append(lambda: i) >return a > > b = m() > for n in range(3): print(b[n]()) # => 2 2 2 > > ... work the same as this in Ruby: > > def

Re: Why lambda in loop requires default?

2016-03-27 Thread Jussi Piitulainen
gvim writes: > Given that Python, like Ruby, is an object-oriented language why > doesn't this: > > def m(): > a = [] > for i in range(3): a.append(lambda: i) > return a > > b = m() > for n in range(3): print(b[n]()) # => 2 2 2 > > ... wo

Re: Why lambda in loop requires default?

2016-03-27 Thread Jussi Piitulainen
gvim writes: > Given that Python, like Ruby, is an object-oriented language why > doesn't this: > > def m(): > a = [] > for i in range(3): a.append(lambda: i) > return a > > b = m() > for n in range(3): print(b[n]()) # => 2 2 2 I'm going to

Why lambda in loop requires default?

2016-03-27 Thread gvim
Given that Python, like Ruby, is an object-oriented language why doesn't this: def m(): a = [] for i in range(3): a.append(lambda: i) return a b = m() for n in range(3): print(b[n]()) # => 2 2 2 ... work the same as this in Ruby: def m a = [] (0..2).each {|i| a <<

Re: converting boolean filter function to lambda

2015-06-25 Thread Mark Lawrence
On 26/06/2015 01:57, Ethan Furman wrote: On 06/25/2015 05:09 PM, Mark Lawrence wrote: On 26/06/2015 00:59, Chris Angelico wrote: On Fri, Jun 26, 2015 at 1:59 AM, Ethan Furman wrote: My attempt at a lambda function fails: filter(lambda p: (p in c for c in contacts), main) # ['291.792

Re: converting boolean filter function to lambda

2015-06-25 Thread Ethan Furman
On 06/25/2015 05:09 PM, Mark Lawrence wrote: On 26/06/2015 00:59, Chris Angelico wrote: On Fri, Jun 26, 2015 at 1:59 AM, Ethan Furman wrote: My attempt at a lambda function fails: filter(lambda p: (p in c for c in contacts), main) # ['291.792.9001', '291.792.9000'] Be

Re: converting boolean filter function to lambda

2015-06-25 Thread Mark Lawrence
On 26/06/2015 00:59, Chris Angelico wrote: On Fri, Jun 26, 2015 at 1:59 AM, Ethan Furman wrote: My attempt at a lambda function fails: filter(lambda p: (p in c for c in contacts), main) # ['291.792.9001', '291.792.9000'] Besides using a lambda ;) , what have I done wrong?

Re: converting boolean filter function to lambda

2015-06-25 Thread Chris Angelico
On Fri, Jun 26, 2015 at 1:59 AM, Ethan Furman wrote: > My attempt at a lambda function fails: > > filter(lambda p: (p in c for c in contacts), main) > # ['291.792.9001', '291.792.9000'] > > Besides using a lambda ;) , what have I done wrong? This looks like

Re: converting boolean filter function to lambda

2015-06-25 Thread Peter Otten
0 x111'] > main = ['291.792.9001', '291.792.9000'] > > which works: > > filter(phone_found, main) > # ['291.792.9000'] > > My attempt at a lambda function fails: > > filter(lambda p: (p in c for c in contacts), main) > # [

Re: converting boolean filter function to lambda

2015-06-25 Thread Ian Kelly
280 x999', '291.792.9000 x111'] > main = ['291.792.9001', '291.792.9000'] > > which works: > > filter(phone_found, main) > # ['291.792.9000'] > > My attempt at a lambda function fails: > > filter(lambda p: (p in c for c in contacts

converting boolean filter function to lambda

2015-06-25 Thread Ethan Furman
which works: filter(phone_found, main) # ['291.792.9000'] My attempt at a lambda function fails: filter(lambda p: (p in c for c in contacts), main) # ['291.792.9001', '291.792.9000'] Besides using a lambda ;) , what have I done wrong? -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list

Re: Could you explain lambda function to me?

2015-06-02 Thread ast
"fl" a écrit dans le message de news:323866d1-b117-4785-ae24-7d04c49bc...@googlegroups.com... Hi, def make_incrementor(n): ... return lambda x: x + n ... f = make_incrementor(42) f(0) 42 f(1) 43 make_incrementor is a fonction which return a function ! and the returne

Re: Could you explain lambda function to me?

2015-06-02 Thread Chris Kaynor
On Tue, Jun 2, 2015 at 11:14 AM, fl wrote: > Hi, > > I see the description of lambda at the online tutorial, but I cannot > understand it. '42' is transferred to the function. What 'x' value should > be? I do not see it says that it is '0'. And,

Could you explain lambda function to me?

2015-06-02 Thread fl
Hi, I see the description of lambda at the online tutorial, but I cannot understand it. '42' is transferred to the function. What 'x' value should be? I do not see it says that it is '0'. And, what is 'x'? >>> def make_increme

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Steven D'Aprano
Roy Smith wrote: > In article <54ba5a25$0$12991$c3e8da3$54964...@news.astraweb.com>, > Steven D'Aprano wrote: > >> Whitespace is significant in nearly all programming languages, and so it >> should be. Whitespace separates tokens, and lines, and is a natural way >> of writing (at least for peop

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Gregory Ewing
Jussi Piitulainen wrote: I prefer parentheses. They are not nearly as fragile. So do I, but the other day I had occasion to write a small piece of VBScript, and I discovered that it actually *forbids* parens around the arguments to procedure calls (but not function calls). Fortunately, it requ

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Chris Angelico
On Sun, Jan 18, 2015 at 8:56 AM, Gregory Ewing wrote: > Ruby doesn't have that problem because it doesn't > have functions, only methods, and the only thing you > can do with a method in Ruby is call it. So functions aren't first-class objects in Ruby? Bleh. I've become quite accustomed to passin

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Gregory Ewing
Chris Angelico wrote: Every once in a while, someone looks at Py2's print statement and Py3's print function and says, "why not allow function calls without parentheses". This right here is why not. There's also the fact that the parens are needed to distinguish between calling a function and u

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Gregory Ewing
Steven D'Aprano wrote: def a(x=4) x+2 end a + b => 7 a+b => 7 a+ b => 7 a +b => 3 A shiny new penny for any non-Ruby coder who can explain that! Seems pretty obvious to me: the Ruby interpreter is infested with demons. DWIM = Demonic Whim Infers Meaning -- Greg -- https://mail.pyth

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread alister
On Sat, 17 Jan 2015 19:08:21 +, Dan Sommers wrote: > On Sat, 17 Jan 2015 18:44:42 +, Grant Edwards wrote: > >> ... somebody who only knows how to write C++ [though he can do it in >> several different languages]. > > +1 QOTW (brilliant phrases in other threads are off topic and are > dis

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Dan Sommers
On Sat, 17 Jan 2015 18:44:42 +, Grant Edwards wrote: > ... somebody who only knows how to write C++ [though he can do it in > several different languages]. +1 QOTW (brilliant phrases in other threads are off topic and are disqualified) I have also suffered through such maintenance, but I hav

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Grant Edwards
On 2015-01-17, Roy Smith wrote: > In article <54ba39e0$0$13008$c3e8da3$54964...@news.astraweb.com>, > Steven D'Aprano wrote: > >> Every time I think I would like to learn a new language, I quite quickly run >> into some obvious feature that Python has but the newer language lacks, and >> I think

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Grant Edwards
On 2015-01-16, Gregory Ewing wrote: > We're really quite spoiled in Python-land. It's easy > to forget just *how* spoiled we are until you go back > and try to do something in one of the more primitive > languages... I had to do some work in PHP yesterday -- fixing up some code that was written

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread alister
On Sat, 17 Jan 2015 21:33:19 +1100, Steven D'Aprano wrote: > Gregory Ewing wrote: > >> Marko Rauhamaa wrote: >>> Gregory Ewing : >>> If those are 24-bit RGB pixels, you could encode 3 characters in each pixel. >>> >>> Not since Python3. Characters are Unicode now so you'll need to >>> d

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Roy Smith
In article <54ba5a25$0$12991$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Whitespace is significant in nearly all programming languages, and so it > should be. Whitespace separates tokens, and lines, and is a natural way of > writing (at least for people using Western languages)

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Roy Smith
In article , Skip Montanaro wrote: > On Sat, Jan 17, 2015 at 5:59 AM, Jussi Piitulainen > wrote: > > How far do you want to go? Is "a b + c" the same as "a(b) + c" or the > > same as "a(b + c)"? > > I think there is only one practical interpretation, the one that all > shells I'm familiar wit

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Roy Smith
In article <54ba39e0$0$13008$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Every time I think I would like to learn a new language, I quite quickly run > into some obvious feature that Python has but the newer language lacks, and > I think "bugger this for a game of soldiers" and

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Danilo Coccia
Il 17/01/2015 12.07, Marko Rauhamaa ha scritto: > Jussi Piitulainen : > >> a+ b => 7 # a() + b >> a +b => 3 # a(+b) => a(b) => a(1) = 1 + 2 >> >> I'm not quite fond of such surprise in programming language syntax. > > Yes, whoever came up with the idea of whitespace having syntactic > sig

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Chris Angelico
On Sat, Jan 17, 2015 at 9:49 PM, Jussi Piitulainen wrote: > I've only seen small amounts of Ruby code on the net. The only way I > can make some sense of that is if it gets analyzed as follows, using > parentheses for calls: > > a + b => 7 # a() + b => a(4) + b => 4 + 2 + 1 > a+b => 7 # a()

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Jussi Piitulainen
Skip Montanaro writes: > On Sat, Jan 17, 2015 at 5:59 AM, Jussi Piitulainen wrote: > > How far do you want to go? Is "a b + c" the same as "a(b) + c" or > > the same as "a(b + c)"? > > I think there is only one practical interpretation, the one that all > shells I'm familiar with have adopted: >

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Seriously, though, I hate the optional semicolon rules of JavaScript > and Go. I dread the day when GvR gets it in his head to allow this > syntax in Python: > >average_drop_rate = cumulative_drop_count / >observation_period > > (although, it could be defined

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Steven D'Aprano
Jussi Piitulainen wrote: > I've only seen small amounts of Ruby code on the net. The only way I > can make some sense of that is if it gets analyzed as follows, using > parentheses for calls: > > a + b => 7 # a() + b => a(4) + b => 4 + 2 + 1 > a+b => 7 # a() + b > a+ b => 7 # a() + b >

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Jussi Piitulainen : > >> a+ b => 7 # a() + b >> a +b => 3 # a(+b) => a(b) => a(1) = 1 + 2 >> >> I'm not quite fond of such surprise in programming language syntax. > > Yes, whoever came up with the idea of whitespace having syntactic > significance! Yes, we shoul

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Marko Rauhamaa
Jussi Piitulainen : > Marko Rauhamaa writes: >> Yes, whoever came up with the idea of whitespace having syntactic >> significance! > > How far do you want to go? [...] > > I prefer parentheses. They are not nearly as fragile. *cough* braces *cough* Seriously, though, I hate the optional semicolo

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Skip Montanaro
On Sat, Jan 17, 2015 at 5:59 AM, Jussi Piitulainen wrote: > How far do you want to go? Is "a b + c" the same as "a(b) + c" or the > same as "a(b + c)"? I think there is only one practical interpretation, the one that all shells I'm familiar with have adopted: a(b, +, c) > And I don't reall

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Jussi Piitulainen: > > > a+ b => 7 # a() + b > > a +b => 3 # a(+b) => a(b) => a(1) = 1 + 2 > > > > I'm not quite fond of such surprise in programming language > > syntax. > > Yes, whoever came up with the idea of whitespace having syntactic > significance! How fa

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Marko Rauhamaa
Jussi Piitulainen : > a+ b => 7 # a() + b > a +b => 3 # a(+b) => a(b) => a(1) = 1 + 2 > > I'm not quite fond of such surprise in programming language syntax. Yes, whoever came up with the idea of whitespace having syntactic significance! Marko -- https://mail.python.org/mailman/listinf

  1   2   3   4   5   6   7   8   9   10   >