For example, we have an if-else statement which could be reduced to a single line:  condition = True # condition = False  if condition:     foo = 'Whatever' else:     foo = 'Nevermind'   The default reduce-technique is to do that:  foo = 'Whatever' if condition else 'Nevermind'   But also we can do it this way:  foo = {True:'Whatever', False:'Nevermind'}[condition]   Is that good/bad? Why?Is there any other way to shrink if-else statement?IMHO, in the dict-case readability is pretty cool since we can see all possible condition values in a well-structured form.
852
If Python does not have a ternary conditional operator, is it possible to simulate one using other language constructs?
38518
How do I produce a conditional expression with large brackets? For example: X = 0 if a=1, 1 otherwise, with a large left bracket and specifying each condition in a line?
31131
Assuming String a and b:  a += b a = a.concat(b)   Under the hood, are they the same thing?  Here is concat decompiled as reference. I'd like to be able to decompile the + operator as well to see what that does.  public String concat(String s) {      int i = s.length();     if (i == 0) {         return this;     }     else {         char ac[] = new char[count + i];         getChars(0, count, ac, 0);         s.getChars(0, i, ac, count);         return new String(0, count + i, ac);     } }
2664
In python, is there a difference between calling clear() and assigning {} to a dictionary? If yes, what is it? Example:d = {"stuff":"things"} d.clear()   #this way d = {}      #vs this way
27093
I occasionally see the list slice syntax used in Python code like this:  newList = oldList[:]   Surely this is just the same as:  newList = oldList   Or am I missing something?
65718
Conditionals in English are usually formed by using if with normal word order; but for the three past (subjunctive) forms were, should, and had, it is also possible to express the conditional through subject–auxiliary inversion alone, with no if in the conditional clause.  Does forming conditionals in this manner differ semantically from if-conditionals? Is some aspect of the conditional statement or the conditionality emphasised more in one version than in the other? Or are there differences in how and when they are used? Or are they simply completely interchangeable?  For example:     If I were you, I would try it again   Were I you, I would try it again      If I had seen it, I would have told you   Had I seen it, I would have told you      If you should drink, don’t get behind the wheel   Should you drink, don’t get behind the wheel
97441
So per  we have the following definition for *:     Expands to the positional parameters, starting from one, initially   producing one field for each positional parameter that is set. When   the expansion occurs in a context where field splitting will be   performed, any empty fields may be discarded and each of the non-empty   fields shall be further split as described in Field Splitting. When   the expansion occurs in a context where field splitting will not be   performed, the initial fields shall be joined to form a single field   with the value of each parameter separated by the first character of   the IFS variable if IFS contains at least one character, or separated   by a  if IFS is unset, or with no separation if IFS is set to a   null string.   For a vast majority of people we are aware of the famous ARG_MAX limitation:  $ getconf ARG_MAX 2621440   which may lead to:  $ cat * | sort -u &gt; /tmp/bla.txt -bash: /bin/cat: Argument list too long   Thankfully the good people behind bash ([include all POSIX-like others]) provided us with printf as a built-in, so we can simply:  printf '%s\0' * | sort -u --files0-from=- &gt; /tmp/bla.txt   And everything is transparent for the user.  Could someone please let me know why this is so trivial to bypass the ARG_MAX limitation using a built-in command and why it is so damn hard to provide a conforming POSIX shell interpreter which would handle gracefully * special parameter to a standalone executable:  $ cat *   Would that break something ? I am not asking bash people to provide cat as a built-in, I am solely interested in the order of operations and why is * expanded in different behavior depending whether the command is build-in or is a standalone executable.
21288
It seems that   if (x=y) { .... }   instead of  if (x==y) { ... }    is a root of many evils.  Why don't all compilers mark it as error instead of a configurable warning?  I'm interested in finding out cases where the construct if (x=y) is useful.
23695
I am using \if condition in a custom command in my LaTeX document. I would like to know where I can find some good explanation about \if command. I followed a  but it's just an example; there are not any explanation.
104592
I am running some script which passing the string argument and I want to do if else statement shown as below:  if [ $1 != '' ] &amp;&amp; [ $2 != '' ] then      do something.....   but it shown Error too many argument. Why?
5199
Is ∅ equivalent to {∅}? I think they are, but I am not sure? If anyone could clarify, that would be great. Thank you!
21433
I am writing a document for a software which has two versions. Most of the content in the document is the same except few specific details. Right now, I am using the conditionals to build the document for a specific file, like so,   \usepackage{etoolbox} .. \newtoggle{version5}     \togglefalse{version5}  \iftoggle{version5} {     \title{Version 5 document} } {     \title{Version 6 document} }  \begin{document}     \chapter{Chapter 1}         \iftoggle{version5} {             \section{Version 5 section}         } {             \section{Version 6 section}         } \end{document}   This works prefectly, but the problem is everytime I need either of the document, I need to toggle the variables each time. Is there a way to build both the document in a single run?
94627
Sometimes I hear sentences that sound conditional to me, just because of the (unassertive) ordering of the words. I don't know if I can come up with a proper example. Consider this:          I'd be a lot better, had she stayed with me.        And I guess it's equivalent to this conditional form: If she had stayed with me, I would have been a lot better.  So, this is my question: In what ways can you make a sentence conditional without using conditional conjunctions (if, unless, etc)? And what are their equivalent conditional forms?
14845
Is it possible to use If Else conditional in a LINQ query?  Something like  from p in db.products if p.price&gt;0 select new {   Owner=from q in db.Users         select q.Name } else select new {    Owner = from r in db.ExternalUsers             select r.Name }
22801
In many languages assignments are legal in conditions. I never understood the reason behind this. Why would you write:  if (var1 = var2) {   ... }   instead of:  var1 = var2; if (var1) {   ... }
45364
I have seen the following technique used many times on many different shells, to test if a variable is empty:  if [ "x$1" = "x" ]; then      # Variable is empty fi   Are there any advantages on using this over the more canonical if [ -z "$1" ]? Could it be a portability issue?
18277
Given a dictionary, how can I find out if a given key in that dictionary has already been set to a non-None value?  I.e., I want to do this:  my_dict = {}  if (my_dict[key] != None):   my_dict[key] = 1 else:   my_dict[key] += 1   I.e., I want to increment the value if there's already one there, or set it to 1 otherwise.