Python if not == vs if !=

Using dis to look at the bytecode generated for the two versions: not == 4 0 LOAD_FAST 0 (foo) 3 LOAD_FAST 1 (bar) 6 COMPARE_OP 2 (==) 9 UNARY_NOT 10 RETURN_VALUE != 4 0 LOAD_FAST 0 (foo) 3 LOAD_FAST 1 (bar) 6 COMPARE_OP 3 (!=) 9 RETURN_VALUE The latter has fewer operations, and is therefore … Read more

Can I use the range operator with if statement in Swift?

You can use the “pattern-match” operator ~=: if 200 … 299 ~= statusCode { print(“success”) } Or a switch-statement with an expression pattern (which uses the pattern-match operator internally): switch statusCode { case 200 … 299: print(“success”) default: print(“failure”) } Note that ..< denotes a range that omits the upper value, so you probably want … Read more

How to prevent ifelse() from turning Date objects into numeric objects

You may use data.table::fifelse (data.table >= 1.12.3) or dplyr::if_else. data.table::fifelse Unlike ifelse, fifelse preserves the type and class of the inputs. library(data.table) dates <- fifelse(dates == ‘2011-01-01’, dates – 1, dates) str(dates) # Date[1:5], format: “2010-12-31” “2011-01-02” “2011-01-03” “2011-01-04” “2011-01-05” dplyr::if_else From dplyr 0.5.0 release notes: [if_else] have stricter semantics that ifelse(): the true and … Read more

What is a good practice to check if an environmental variable exists or not?

Use the first; it directly tries to check if something is defined in environ. Though the second form works equally well, it’s lacking semantically since you get a value back if it exists and only use it for a comparison. You’re trying to see if something is present in environ, why would you get just … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)