Since there was talk of if-then-else not being allowed in lambda
expressions, the following is from "Dive into Python"
The and-or conditional expression trick from page 41 of "Dive into
Python"
Wrap the arguments in lists and then take the first element.
>>a = "" b = "second" (1 and [a] or [b])[0]
''
--
Regards,
Casey 5 1520
Casey Hawthorne wrote:
Since there was talk of if-then-else not being allowed in lambda
expressions, the following is from "Dive into Python"
The and-or conditional expression trick from page 41 of "Dive into
Python"
Wrap the arguments in lists and then take the first element.
>>>a = "" b = "second" (1 and [a] or [b])[0]
''
# python 2.5
>>a, b = "", 0 a if False else b
0
>>a if True else b
''
Time to tear out that page. Really.
Peter
# python 2.5
>a, b = "", 0 a if False else b
0
>a if True else b
''
Time to tear out that page. Really.
Not quite - 2.5 hasn't been released in its final version yet, and many
projects I should imagine will take a while to upgrade.
Ant wrote:
>
># python 2.5
>>a, b = "", 0 a if False else b
0
>>a if True else b
''
Time to tear out that page. Really.
Not quite - 2.5 hasn't been released in its final version yet, and many
projects I should imagine will take a while to upgrade.
Ok, use
if cond:
value = ... # expression that must not be evaluated unless it absolutely
# has to be
else:
value = ... # same thing
which will withstand the test of time. Now tear out that page...
Peter
Peter Otten wrote:
Ant wrote:
>>># python 2.5
>>a, b = "", 0 >>a if False else b
0
>>a if True else b
''
Time to tear out that page. Really.
Not quite - 2.5 hasn't been released in its final version yet, and many projects I should imagine will take a while to upgrade.
Ok, use
if cond:
value = ... # expression that must not be evaluated unless it absolutely
# has to be
else:
value = ... # same thing
which will withstand the test of time.
But isn't allowed in a lambda !-)
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Bruno Desthuilliers wrote:
But isn't allowed in a lambda !-)
Then tear out that lambada page, too, I was tempted to say, but I will
desist. For now...
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mike P |
last post by:
I've just been reading up on lambda expressions and how you can use them
to make selections from XML in a similar syntax to SQL. Does this mean
no more need for Xpath? I have used Xpath once or...
|
by: beginner |
last post by:
Hi All,
It is really convenient to use nested functions and lambda
expressions. What I'd like to know is if Python compiles fn_inner()
only once and change the binding of v every time fn_outer()...
|
by: dspfun |
last post by:
Hi!
Are suffixes allowed on expressions?
For example, is the following allowed:
#define SECONDS_PER_YEAR (60 * 60 * 365) UL
I found this in a C test at...
|
by: Cowboy \(Gregory A. Beamer\) |
last post by:
If you have a tough time getting your head around Lambda Expressions, see if
this blog entry helps:
http://tinyurl.com/4yeckd
I would gladly welcome comments, critiques and questions, as I am...
|
by: raylopez99 |
last post by:
Took a look at all the fuss about "lambda expressions" from Jon
Skeet's excellent book "C# in Depth". Jon has an example, reproduced
below (excerpt) on lambda expressions.
My n00b take: it's...
|
by: Pavel Minaev |
last post by:
On Aug 14, 1:37 pm, raylopez99 <raylope...@yahoo.comwrote:
You are, of course, entitled to your opinion, but lambdas are a part
of C# 3.0, and any C# developer has to know their ins and outs if...
|
by: raylopez99 |
last post by:
The headline says it all. Great minds think alike: read the blog
below from three years ago, as endorsed by Ritchie, who coinvented
C.
BTW the below lambda expression code will not work (.Where...
|
by: Stefan Hoffmann |
last post by:
hi @all,
I stumbled upon this one:
MethodInvoker listMethodInvoker =
() =list = Broker.RetrieveList<T>();
This works fine for me under VS2008 and target .Net 2.0. The question
is: Why?
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| | |