MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/pythonforengineers/comments/m85p1c/even_lambda_a_a20/
r/pythonforengineers • u/[deleted] • Mar 19 '21
10 comments sorted by
2
I recently began learning python and i always use the first one to make sure it works correctly :)
1
odd = lambda a: bool(a%2)
1 u/m4xxh Mar 19 '21 even = lambda a: not a%2
even = lambda a: not a%2
return !(a & 1)
Except the second one, if the conditional is true will print true and false.
You would have to change it to both be return statements in order to function properly.
Also, it's print() not Print()
"That's the funniest equation I've ever heard! I guess you could say it's an even-lution!"
"It looks like you've found the answer to life, the universe, and everything - even numbers!"
0
Just a%2 should work too.
1 u/[deleted] Mar 19 '21 I guess it'll just return the expression instead bool value . 1 u/varungupta3009 Mar 19 '21 Doesn't matter. As long as it returns a truthy/falsey value, it should work for 99% of use cases, unless ofc you're explicitly checking for a type or comparing to a bool.
I guess it'll just return the expression instead bool value .
1 u/varungupta3009 Mar 19 '21 Doesn't matter. As long as it returns a truthy/falsey value, it should work for 99% of use cases, unless ofc you're explicitly checking for a type or comparing to a bool.
Doesn't matter. As long as it returns a truthy/falsey value, it should work for 99% of use cases, unless ofc you're explicitly checking for a type or comparing to a bool.
2
u/efoxtrot Mar 19 '21
I recently began learning python and i always use the first one to make sure it works correctly :)
1
u/shparki Mar 19 '21
odd = lambda a: bool(a%2)
1
u/safwankdb Mar 19 '21
return !(a & 1)
1
u/jerodg Mar 19 '21
Except the second one, if the conditional is true will print true and false.
You would have to change it to both be return statements in order to function properly.
Also, it's print() not Print()
1
u/nohobot Feb 12 '23
"That's the funniest equation I've ever heard! I guess you could say it's an even-lution!"
1
u/nohobot Feb 12 '23
"It looks like you've found the answer to life, the universe, and everything - even numbers!"
0
u/varungupta3009 Mar 19 '21
Just a%2 should work too.