Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
the PHP ternary operator equivalent on Python
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Daniel Crespo, post: 1850216"] WHY WHY WHY the obsession with one-liners? What is wrong with the good old Let me tell you something: I'm not a one-liner coder, but sometimes It is necesary. For example: I need to translate data from a DataField to Another. def Evaluate(condition,truepart,falsepart): if condition: return truepart else: return falsepart dOldDataFields = {} dNewDataFields = {} dNewDataFields = { 'CODE': dOldDataFields['CODEDATA'], 'DATE': dOldDataFields['DATE'], 'CONTACT': Evaluate(dOldDataFields['CONTACTTYPE']==2, dOldDataFields['FIRSTCONTACT'], dOldDataFields['SECONDCONTACT']) } With this, I created a new dic very easy, saving in dNewDataFields['CONTACT'] the value of dOldDataFields['FIRSTCONTACT'] or the value of dOldDataFields['SECONDCONTACT'] depending on dOldDataFields['CONTACTTYPE']. How you do this in a practic way without the use of one-line code? It is needed! You can't avoid it! Even using a = [if_false_expr, if_true_expr][predicate] or a function, you'll always have to use a one-line code (for this purpose, of course). Daniel [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
the PHP ternary operator equivalent on Python
Top