compare
Difference between period and comma when concatenating with echo versus return?
return only allows one expression, but echo allows a list of expressions where each expression is separated by a comma. But note that since echo is not a function but a special language construct, wrapping the expression list in parenthesis is illegal.
Dictionary merge by updating but not overwriting if value exists
Just switch the order: z = dict(d2.items() + d1.items()) By the way, you may also be interested in the potentially faster update method. In Python 3, you have to cast the view objects to lists first: z = dict(list(d2.items()) + list(d1.items())) If you want to special-case empty strings, you can do the following: def mergeDictsOverwriteEmpty(d1, … Read more
How can I use in_array if the needle is an array?
Use array_diff(): $arr1 = array(1,2,3); $arr2 = array(1,2,3,4,5,6,7); $arr3 = array_diff($arr1, $arr2); if (count($arr3) == 0) { // all of $arr1 is in $arr2 }
Linq where clause compare only date value without time value
There is also EntityFunctions.TruncateTime or DbFunctions.TruncateTime in EF 6.0 or later
How to tell if a date is between two other dates?
If you convert all your dates to datetime.date, you can write the following: if start <= date <= end: print(“in between”) else: print(“No!”)
Why is one string greater than the other when comparing strings in JavaScript?
Because, as in many programming languages, strings are compared lexicographically. You can think of this as a fancier version of alphabetical ordering, the difference being that alphabetic ordering only covers the 26 characters a through z. This answer is in response to a java question, but the logic is exactly the same. Another good one: … Read more
Efficient way to compare version strings in Java [duplicate]
Requires commons-lang3-3.8.1.jar for string operations. /** * Compares two version strings. * * Use this instead of String.compareTo() for a non-lexicographical * comparison that works for version strings. e.g. “1.10”.compareTo(“1.6”). * * @param v1 a string of alpha numerals separated by decimal points. * @param v2 a string of alpha numerals separated by decimal points. … Read more
How would you compare two XML Documents?
Microsoft has an XML diff API that you can use. Unofficial NuGet: https://www.nuget.org/packages/XMLDiffPatch.
In Python, is there a concise way of comparing whether the contents of two text files are the same?
The low level way: from __future__ import with_statement with open(filename1) as f1: with open(filename2) as f2: if f1.read() == f2.read(): … The high level way: import filecmp if filecmp.cmp(filename1, filename2, shallow=False): …