Re: Creating lambdas inside generator expression

2022-06-29 Thread Chris Angelico
On Thu, 30 Jun 2022 at 02:49, Johannes Bauer wrote: > But now consider what happens when we create the lambdas inside a list > comprehension (in my original I used a generator expresison, but the > result is the same). Can you guess what happens when we create conds > like this? > > conds = [ lamb

Re: WHAT THE ERROR ON MY CODE???

2022-06-29 Thread Calvin Spealman
You also forgot to include any information about an error or problem you got in using this code. We can't help you if you don't have an actual question to ask. ‪On Wed, Jun 29, 2022 at 1:36 AM ‫נתי שטרן‬‎ wrote:‬ > Sorry but i forgor to delete this token data > > בתאריך יום שלישי, 28 ביוני 2022

Re: Creating lambdas inside generator expression

2022-06-29 Thread Antoon Pardon
Or you could try this as an alternative: conds = [ (lambda code: lambda msg: msg.hascode(code))(z) for z in ("foo", "bar") ] Op 29/06/2022 om 12:43 schreef Johannes Bauer: Aha! conds = [ lambda msg, z = z: msg.hascode(z) for z in ("foo", "bar") ] Is what I was looking for to explicitly use

Creating lambdas inside generator expression

2022-06-29 Thread Johannes Bauer
Hi list, I've just encounted something that I found extremely unintuitive and would like your feedback. This bit me *hard*, causing me to question my sanity for a moment. Consider this minimal example code (Py 3.10.4 on Linux x64): class Msg(): def hascode(self, value): p

Re: Creating lambdas inside generator expression

2022-06-29 Thread Johannes Bauer
Aha! conds = [ lambda msg, z = z: msg.hascode(z) for z in ("foo", "bar") ] Is what I was looking for to explicitly use the value of z. What a caveat, didn't see that coming. Learning something new every day. Cheers, Joe Am 29.06.22 um 11:50 schrieb Johannes Bauer: > Hi list, > > I've just en